From bf629f3adbb636d987d93a52c3fd8629e8944394 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Mon, 6 Jul 2026 11:17:57 +0900 Subject: [PATCH] Extract the reduced-frame guard into ensure_reduced_frame() The RF_NOT_DETERMINED guard lived in row_is_in_reduced_frame(), while the per-row match drive reached it through a (void) cast that discarded the result. Extract the guard into an idempotent helper and call it from both sites. No behavior change. --- src/backend/executor/nodeWindowAgg.c | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index e4e97a6ed95..9ffca036953 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -236,6 +236,7 @@ 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 clear_reduced_frame(WindowAggState *winstate); static int get_reduced_frame_status(WindowAggState *winstate, int64 pos); @@ -2532,8 +2533,8 @@ ExecWindowAgg(PlanState *pstate) * leave the match state behind currentpos. */ Assert(winstate->nav_winobj != NULL); - (void) row_is_in_reduced_frame(winstate->nav_winobj, - winstate->currentpos); + ensure_reduced_frame(winstate->nav_winobj, + winstate->currentpos); } /* @@ -4255,13 +4256,7 @@ row_is_in_reduced_frame(WindowObject winobj, int64 pos) return rtn; } - state = get_reduced_frame_status(winstate, pos); - - if (state == RF_NOT_DETERMINED) - { - update_frameheadpos(winstate); - update_reduced_frame(winobj, pos); - } + ensure_reduced_frame(winobj, pos); state = get_reduced_frame_status(winstate, pos); @@ -4289,6 +4284,26 @@ row_is_in_reduced_frame(WindowObject winobj, int64 pos) return rtn; } +/* + * ensure_reduced_frame + * Drive the row pattern match forward so pos is resolved. + * + * Idempotent: a pos already determined is left untouched, so callers may + * invoke this repeatedly for the same row (once per row to track the row + * scan, and again when a window function accesses the frame). + */ +static void +ensure_reduced_frame(WindowObject winobj, int64 pos) +{ + WindowAggState *winstate = winobj->winstate; + + if (get_reduced_frame_status(winstate, pos) == RF_NOT_DETERMINED) + { + update_frameheadpos(winstate); + update_reduced_frame(winobj, pos); + } +} + /* * clear_reduced_frame * Clear reduced frame status