From 27109165b8c6764089bf106c750c63b7e45dc7a1 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Sat, 2 May 2026 00:10:55 +0900 Subject: [PATCH 32/40] Fix A1 frame optimization bypass test in rpr_integration The non-RPR baseline used count(*) with a default frame. count's prosupport does not handle SupportRequestOptimizeWindowClause, so optimize_window_clauses() was never invoked on the baseline; the absence of an explicit frame in EXPLAIN was a ruleutils default-frame omission, not the result of any rewrite. The plan diff therefore did not actually exercise the RPR guard. Use row_number() instead, which has prosupport handling that request, and give both queries the same explicit input frame (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING). The non-RPR plan now shows the rewritten frame (ROWS UNBOUNDED PRECEDING) while the RPR plan keeps it intact, making the guard's effect observable in EXPLAIN. Reword the block comment to describe the actual planner action, and align the inline labels with the surrounding A2/A3 sections. --- src/test/regress/expected/rpr_integration.out | 30 +++++++++++-------- src/test/regress/sql/rpr_integration.sql | 26 +++++++++------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/test/regress/expected/rpr_integration.out b/src/test/regress/expected/rpr_integration.out index 9dbf0f43c8f..0cc79b75601 100644 --- a/src/test/regress/expected/rpr_integration.out +++ b/src/test/regress/expected/rpr_integration.out @@ -38,26 +38,32 @@ INSERT INTO rpr_integ VALUES -- ============================================================ -- A1. Frame optimization bypass -- ============================================================ --- optimize_window_clauses() must not apply frame optimization to RPR windows. --- Non-RPR case: frame can be optimized (RANGE -> ROWS conversion, etc.). --- RPR case: frame must stay as specified (ROWS BETWEEN CURRENT ROW AND --- UNBOUNDED FOLLOWING). --- Non-RPR window with default frame -> frame optimization applied +-- Verify that optimize_window_clauses() does not apply frame +-- optimization to RPR windows. Both queries below use the same input +-- frame (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) with +-- row_number(), whose prosupport handles +-- SupportRequestOptimizeWindowClause and triggers frame rewriting. +-- In the non-RPR baseline the planner rewrites the frame to ROWS +-- UNBOUNDED PRECEDING, while in the RPR case the guard in +-- optimize_window_clauses() blocks the rewrite and the frame is +-- preserved as specified. +-- Non-RPR baseline: the planner rewrites the frame to ROWS UNBOUNDED PRECEDING. EXPLAIN (COSTS OFF) -SELECT count(*) OVER w FROM rpr_integ -WINDOW w AS (ORDER BY id); - QUERY PLAN ------------------------------------ +SELECT row_number() OVER w FROM rpr_integ +WINDOW w AS (ORDER BY id + ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING); + QUERY PLAN +------------------------------------------------------- WindowAgg - Window: w AS (ORDER BY id) + Window: w AS (ORDER BY id ROWS UNBOUNDED PRECEDING) -> Sort Sort Key: id -> Seq Scan on rpr_integ (5 rows) --- RPR window -> frame optimization must NOT change the frame +-- RPR case: the frame is preserved as specified. EXPLAIN (COSTS OFF) -SELECT count(*) OVER w FROM rpr_integ +SELECT row_number() OVER w FROM rpr_integ WINDOW w AS (ORDER BY id ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING PATTERN (A B+) diff --git a/src/test/regress/sql/rpr_integration.sql b/src/test/regress/sql/rpr_integration.sql index 7d70f5e4b98..6d47728e911 100644 --- a/src/test/regress/sql/rpr_integration.sql +++ b/src/test/regress/sql/rpr_integration.sql @@ -40,19 +40,25 @@ INSERT INTO rpr_integ VALUES -- ============================================================ -- A1. Frame optimization bypass -- ============================================================ --- optimize_window_clauses() must not apply frame optimization to RPR windows. --- Non-RPR case: frame can be optimized (RANGE -> ROWS conversion, etc.). --- RPR case: frame must stay as specified (ROWS BETWEEN CURRENT ROW AND --- UNBOUNDED FOLLOWING). - --- Non-RPR window with default frame -> frame optimization applied +-- Verify that optimize_window_clauses() does not apply frame +-- optimization to RPR windows. Both queries below use the same input +-- frame (ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) with +-- row_number(), whose prosupport handles +-- SupportRequestOptimizeWindowClause and triggers frame rewriting. +-- In the non-RPR baseline the planner rewrites the frame to ROWS +-- UNBOUNDED PRECEDING, while in the RPR case the guard in +-- optimize_window_clauses() blocks the rewrite and the frame is +-- preserved as specified. + +-- Non-RPR baseline: the planner rewrites the frame to ROWS UNBOUNDED PRECEDING. EXPLAIN (COSTS OFF) -SELECT count(*) OVER w FROM rpr_integ -WINDOW w AS (ORDER BY id); +SELECT row_number() OVER w FROM rpr_integ +WINDOW w AS (ORDER BY id + ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING); --- RPR window -> frame optimization must NOT change the frame +-- RPR case: the frame is preserved as specified. EXPLAIN (COSTS OFF) -SELECT count(*) OVER w FROM rpr_integ +SELECT row_number() OVER w FROM rpr_integ WINDOW w AS (ORDER BY id ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING PATTERN (A B+) -- 2.50.1 (Apple Git-155)