From 8689d0011469f226cbcf4cd0489c31118157a5ca Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Tue, 9 Jun 2026 16:24:29 +0800
Subject: [PATCH v47 4/4] another v47 misc refactoring

Improve comments accuracy in parse_rpr.c and regression tests

Tighten comments in parse_rpr.c to better reflect what the code
actually does: rpSkipTo and initial are simple flag assignments,
not clause transformations, so describe them as such. Also remove
the stale reference to optimizer/plan/rpr.c from the file header,
since pattern optimization details belong there, not here.

In the regression tests, remove the redundant "INITIAL clause"
section header, clarify that SEEK mode is not supported, and drop
the specific reference to optimizer/plan/rpr.c from the pattern
optimization test section header.
---
 src/backend/parser/parse_rpr.c         | 16 ++++++----------
 src/test/regress/expected/rpr_base.out |  5 ++---
 src/test/regress/sql/rpr_base.sql      |  6 ++----
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/src/backend/parser/parse_rpr.c b/src/backend/parser/parse_rpr.c
index d12a0d45c9..86e8fbfeb9 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 PATTERN/SKIP TO/INITIAL flags
  *
  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
@@ -70,8 +67,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)
  *
@@ -177,16 +174,15 @@ 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 */
 	wc->defineClause = transformDefineClause(pstate, wc, windef, targetlist);
 
-	/* Store PATTERN AST for deparsing */
 	wc->rpPattern = windef->rpCommonSyntax->rpPattern;
 }
 
diff --git a/src/test/regress/expected/rpr_base.out b/src/test/regress/expected/rpr_base.out
index 428ae0ca6a..39011ff91a 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 d26e2ec706..893d0fe208 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.34.1

