From e1ae1a2a207ff8151526448f7fcd3bb70a3193d8 Mon Sep 17 00:00:00 2001 From: jian he Date: Thu, 8 Oct 2026 18:55:59 +0800 Subject: [PATCH v54 1/3] Use WindowAggState instead of WindowObject in rpr routines Consistently using WindowAggState accross all of RPR routines. Most of RPR case, no need WindowObject. based on https://github.com/assam258-5892/postgres/tree/RPR-20260930 --- src/backend/executor/nodeWindowAgg.c | 34 ++++++++++++---------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index 01cec0f849..747c4d6a5c 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -250,17 +250,17 @@ static void put_notnull_info(WindowObject winobj, int64 pos, int argno, bool isnull); static bool rpr_is_defined(WindowAggState *winstate); static int64 row_is_in_reduced_frame(WindowObject winobj, int64 pos); -static void ensure_reduced_frame(WindowObject winobj, int64 pos); +static void ensure_reduced_frame(WindowAggState *winstate, int64 pos); static void clear_reduced_frame(WindowAggState *winstate); static int get_reduced_frame_status(WindowAggState *winstate, int64 pos); static void advance_nav_mark(WindowAggState *winstate, int64 currentPos); -static void advance_reduced_frame_nfa(WindowObject winobj, +static void advance_reduced_frame_nfa(WindowAggState *winstate, RPRNFAContext *targetCtx); -static void update_reduced_frame(WindowObject winobj, int64 pos); +static void update_reduced_frame(WindowAggState *winstate, int64 pos); /* Forward declarations - DEFINE row evaluation */ -static bool rpr_prepare_row(WindowObject winobj, int64 pos, RPRVarMatch *varMatched); +static bool rpr_prepare_row(WindowAggState *winstate, int64 pos, RPRVarMatch *varMatched); static void build_define_offsets(WindowAggState *winstate, List *defineClause); static void resolve_nav_offsets(WindowAggState *winstate); static void resolve_one_nav(RPRNavOffsets *entry, EvalDefineOffsetsContext *context); @@ -2586,8 +2586,7 @@ ExecWindowAgg(PlanState *pstate) * leave the match state behind currentpos. */ Assert(winstate->nav_winobj != NULL); - ensure_reduced_frame(winstate->nav_winobj, - winstate->currentpos); + ensure_reduced_frame(winstate, winstate->currentpos); } /* @@ -4496,7 +4495,7 @@ row_is_in_reduced_frame(WindowObject winobj, int64 pos) return rtn; } - ensure_reduced_frame(winobj, pos); + ensure_reduced_frame(winstate, pos); state = get_reduced_frame_status(winstate, pos); @@ -4533,14 +4532,12 @@ row_is_in_reduced_frame(WindowObject winobj, int64 pos) * scan, and again when a window function accesses the frame). */ static void -ensure_reduced_frame(WindowObject winobj, int64 pos) +ensure_reduced_frame(WindowAggState *winstate, int64 pos) { - WindowAggState *winstate = winobj->winstate; - if (get_reduced_frame_status(winstate, pos) == RF_NOT_DETERMINED) { update_frameheadpos(winstate); - update_reduced_frame(winobj, pos); + update_reduced_frame(winstate, pos); } } @@ -4669,9 +4666,8 @@ advance_nav_mark(WindowAggState *winstate, int64 currentPos) * evaluations are shared across all active contexts. */ static void -advance_reduced_frame_nfa(WindowObject winobj, RPRNFAContext *targetCtx) +advance_reduced_frame_nfa(WindowAggState *winstate, RPRNFAContext *targetCtx) { - WindowAggState *winstate = winobj->winstate; int64 currentPos; int64 startPos; int64 saved_currentpos = winstate->currentpos; @@ -4710,7 +4706,7 @@ advance_reduced_frame_nfa(WindowObject winobj, RPRNFAContext *targetCtx) winstate->nav_match_start = targetCtx->matchStartRow; /* No more rows in partition? Finalize all contexts */ - if (!rpr_prepare_row(winobj, currentPos, winstate->nfaVarMatched)) + if (!rpr_prepare_row(winstate, currentPos, winstate->nfaVarMatched)) { ExecRPRFinalizeAllContexts(winstate, currentPos - 1); /* Clean up dead contexts from finalization */ @@ -4765,9 +4761,8 @@ advance_reduced_frame_nfa(WindowObject winobj, RPRNFAContext *targetCtx) * - Contexts persist across calls, enabling O(n) DEFINE evaluations */ static void -update_reduced_frame(WindowObject winobj, int64 pos) +update_reduced_frame(WindowAggState *winstate, int64 pos) { - WindowAggState *winstate = winobj->winstate; RPRNFAContext *targetCtx = NULL; winstate->rpr_match_start = pos; @@ -4822,7 +4817,7 @@ update_reduced_frame(WindowObject winobj, int64 pos) * is registered below. */ if (targetCtx->states != NULL) - advance_reduced_frame_nfa(winobj, targetCtx); + advance_reduced_frame_nfa(winstate, targetCtx); if (targetCtx->matchedState == NULL) { @@ -4872,15 +4867,14 @@ update_reduced_frame(WindowObject winobj, int64 pos) * opcodes during expression evaluation, which temporarily swap the slot. */ static bool -rpr_prepare_row(WindowObject winobj, int64 pos, RPRVarMatch *varMatched) +rpr_prepare_row(WindowAggState *winstate, int64 pos, RPRVarMatch *varMatched) { - WindowAggState *winstate = winobj->winstate; ExprContext *econtext = winstate->rprContext; TupleTableSlot *slot; /* Fetch current row into temp_slot_1 */ slot = winstate->temp_slot_1; - if (!window_gettupleslot(winobj, pos, slot)) + if (!window_gettupleslot(winstate->nav_winobj, pos, slot)) return false; /* No row exists */ /* Set up 1-slot context: only ecxt_outertuple */ -- 2.34.1