From f81b960cdbb073b492dd6b3afb83d1b4f2578a10 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Thu, 11 Jun 2026 09:41:54 +0900 Subject: [PATCH 77/77] Improve comment accuracy in RPR parse analysis and tests Describe what transformRPR() actually does: it sets the AFTER MATCH SKIP TO and INITIAL flags rather than "storing" or "transforming" those clauses, and simplify the file header by dropping a vague pointer to the planner. In the regression tests, note that SEEK mode is not supported and drop a stale optimizer file-path reference from a comment. --- src/backend/parser/parse_rpr.c | 15 ++++++--------- src/test/regress/expected/rpr_base.out | 5 ++--- src/test/regress/sql/rpr_base.sql | 6 ++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/backend/parser/parse_rpr.c b/src/backend/parser/parse_rpr.c index a1cd5ad8d38..3eaea2be750 100644 --- a/src/backend/parser/parse_rpr.c +++ b/src/backend/parser/parse_rpr.c @@ -7,11 +7,8 @@ * structures during query analysis: * - Validates frame options (must start at CURRENT ROW, no EXCLUDE) * - Validates PATTERN variable count (max RPR_VARID_MAX + 1) - * - Transforms DEFINE clause into TargetEntry list - * - Stores PATTERN/SKIP TO/INITIAL clauses for planner - * - * Pattern optimization and compilation to NFA bytecode happens later - * in the planner (see optimizer/plan/rpr.c). + * - Transforms DEFINE clause + * - Stores the PATTERN AST and the SKIP TO/INITIAL flags * * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California @@ -67,8 +64,8 @@ static bool define_walker(Node *node, void *context); * * Validates and transforms RPR clauses from parse tree to planner structures: * - Validates frame options (must start at CURRENT ROW, no EXCLUDE) - * - Stores AFTER MATCH SKIP TO clause - * - Stores SEEK/INITIAL clause + * - Set AFTER MATCH SKIP TO flag + * - Set SEEK/INITIAL flag * - Transforms DEFINE clause into TargetEntry list * - Stores PATTERN AST for deparsing (optimization happens in planner) * @@ -174,10 +171,10 @@ transformRPR(ParseState *pstate, WindowClause *wc, WindowDef *windef, windef->frameLocation >= 0 ? windef->frameLocation : windef->location)); - /* Transform AFTER MATCH SKIP TO clause */ + /* Assign AFTER MATCH SKIP TO flag */ wc->rpSkipTo = windef->rpCommonSyntax->rpSkipTo; - /* Transform SEEK or INITIAL clause */ + /* Assign INITIAL flag */ wc->initial = windef->rpCommonSyntax->initial; /* Transform DEFINE clause into list of TargetEntry's */ diff --git a/src/test/regress/expected/rpr_base.out b/src/test/regress/expected/rpr_base.out index f73758ee22d..41541898f5a 100644 --- a/src/test/regress/expected/rpr_base.out +++ b/src/test/regress/expected/rpr_base.out @@ -1927,7 +1927,6 @@ ORDER BY type, id; (16 rows) DROP TABLE rpr_skip; --- INITIAL clause CREATE TABLE rpr_init (id INT, val INT); INSERT INTO rpr_init VALUES (1, 10), (2, 20), (3, 30), (4, 40); -- Explicit INITIAL @@ -1971,7 +1970,7 @@ DROP TABLE rpr_init; -- SEEK CREATE TABLE rpr_seek (id INT, val INT); INSERT INTO rpr_seek VALUES (1, 10); --- SEEK keyword +-- SEEK keyword, SEEK mode is not supported SELECT COUNT(*) OVER w FROM rpr_seek WINDOW w AS ( @@ -3684,7 +3683,7 @@ WINDOW w1 AS ( -- ============================================================ -- Pattern Optimization Tests -- ============================================================ --- Tests for pattern optimization in optimizer/plan/rpr.c +-- Tests for pattern optimization -- Use EXPLAIN to verify optimized pattern (shown as "Pattern: ...") CREATE TABLE rpr_plan (id INT, val INT); INSERT INTO rpr_plan VALUES diff --git a/src/test/regress/sql/rpr_base.sql b/src/test/regress/sql/rpr_base.sql index 7bb45b6bcf4..fcefd59de4a 100644 --- a/src/test/regress/sql/rpr_base.sql +++ b/src/test/regress/sql/rpr_base.sql @@ -1389,8 +1389,6 @@ ORDER BY type, id; DROP TABLE rpr_skip; --- INITIAL clause - CREATE TABLE rpr_init (id INT, val INT); INSERT INTO rpr_init VALUES (1, 10), (2, 20), (3, 30), (4, 40); @@ -1424,7 +1422,7 @@ DROP TABLE rpr_init; CREATE TABLE rpr_seek (id INT, val INT); INSERT INTO rpr_seek VALUES (1, 10); --- SEEK keyword +-- SEEK keyword, SEEK mode is not supported SELECT COUNT(*) OVER w FROM rpr_seek WINDOW w AS ( @@ -2444,7 +2442,7 @@ WINDOW w1 AS ( -- ============================================================ -- Pattern Optimization Tests -- ============================================================ --- Tests for pattern optimization in optimizer/plan/rpr.c +-- Tests for pattern optimization -- Use EXPLAIN to verify optimized pattern (shown as "Pattern: ...") CREATE TABLE rpr_plan (id INT, val INT); -- 2.50.1 (Apple Git-155)