nocfbot-0055-Fix-a-mislabeled-INITIAL-test-in-row-pattern-reco.txt

text/plain

Filename: nocfbot-0055-Fix-a-mislabeled-INITIAL-test-in-row-pattern-reco.txt
Type: text/plain
Part: 52
Message: Re: Row pattern recognition
From a17415a855ba345bbd189869fb0b50334752c404 Mon Sep 17 00:00:00 2001
From: Henson Choi <assam258@gmail.com>
Date: Sat, 6 Jun 2026 07:18:12 +0900
Subject: [PATCH 55/68] Fix a mislabeled INITIAL test in row pattern
 recognition

The "INITIAL Mode" block in rpr_nfa claimed INITIAL was unimplemented
and produced a syntax error.  INITIAL is the default match mode and is
fully supported; the error was only a clause-order violation -- INITIAL
was written before AFTER MATCH SKIP, which the grammar forbids.

Reorder INITIAL after AFTER MATCH SKIP and correct the comments.  The
queries now run and confirm that explicit INITIAL matches the default
mode.  Test-only change.
---
 src/test/regress/expected/rpr_nfa.out | 31 ++++++++++++++++-----------
 src/test/regress/sql/rpr_nfa.sql      | 10 ++++-----
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/test/regress/expected/rpr_nfa.out b/src/test/regress/expected/rpr_nfa.out
index 829e8251aed..02a5e517b0e 100644
--- a/src/test/regress/expected/rpr_nfa.out
+++ b/src/test/regress/expected/rpr_nfa.out
@@ -3524,10 +3524,8 @@ ORDER BY mode, id;
 
 -- ============================================================
 -- INITIAL Mode (Runtime)
--- Placeholder: INITIAL is not yet implemented (syntax error).
--- Kept here so tests convert to runtime tests when implemented.
 -- ============================================================
--- INITIAL mode (not yet supported - produces syntax error)
+-- Explicit INITIAL (after AFTER MATCH SKIP, per the grammar); same as the default
 WITH test_initial_mode AS (
     SELECT * FROM (VALUES
         (1, ARRAY['_']),  -- Unmatched
@@ -3544,15 +3542,21 @@ FROM test_initial_mode
 WINDOW w AS (
     ORDER BY id
     ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
-    INITIAL
     AFTER MATCH SKIP TO NEXT ROW
+    INITIAL
     PATTERN (A+)
     DEFINE
         A AS 'A' = ANY(flags)
 );
-ERROR:  syntax error at or near "AFTER"
-LINE 18:     AFTER MATCH SKIP TO NEXT ROW
-             ^
+ id | flags | match_start | match_end 
+----+-------+-------------+-----------
+  1 | {_}   |             |          
+  2 | {A}   |           2 |         3
+  3 | {A}   |           3 |         3
+  4 | {_}   |             |          
+  5 | {A}   |           5 |         5
+(5 rows)
+
 -- Default mode (include all rows)
 WITH test_default_mode AS (
     SELECT * FROM (VALUES
@@ -3584,7 +3588,7 @@ WINDOW w AS (
   5 | {A}   |           5 |         5
 (5 rows)
 
--- Mode difference verification (INITIAL not yet supported - produces syntax error)
+-- Mode equivalence verification: explicit INITIAL equals the default mode
 WITH test_mode_diff AS (
     SELECT * FROM (VALUES
         (1, ARRAY['_']),
@@ -3598,8 +3602,8 @@ FROM (
     WINDOW w AS (
         ORDER BY id
         ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
-        INITIAL
         AFTER MATCH SKIP TO NEXT ROW
+        INITIAL
         PATTERN (A)
         DEFINE A AS 'A' = ANY(flags)
     )
@@ -3617,9 +3621,12 @@ FROM (
     )
 ) sub
 ORDER BY mode;
-ERROR:  syntax error at or near "AFTER"
-LINE 15:         AFTER MATCH SKIP TO NEXT ROW
-                 ^
+  mode   | row_count 
+---------+-----------
+ DEFAULT |         3
+ INITIAL |         3
+(2 rows)
+
 -- ============================================================
 -- Frame Boundary Variations
 -- ============================================================
diff --git a/src/test/regress/sql/rpr_nfa.sql b/src/test/regress/sql/rpr_nfa.sql
index 3bbec496279..213385f143b 100644
--- a/src/test/regress/sql/rpr_nfa.sql
+++ b/src/test/regress/sql/rpr_nfa.sql
@@ -2530,11 +2530,9 @@ ORDER BY mode, id;
 
 -- ============================================================
 -- INITIAL Mode (Runtime)
--- Placeholder: INITIAL is not yet implemented (syntax error).
--- Kept here so tests convert to runtime tests when implemented.
 -- ============================================================
 
--- INITIAL mode (not yet supported - produces syntax error)
+-- Explicit INITIAL (after AFTER MATCH SKIP, per the grammar); same as the default
 WITH test_initial_mode AS (
     SELECT * FROM (VALUES
         (1, ARRAY['_']),  -- Unmatched
@@ -2551,8 +2549,8 @@ FROM test_initial_mode
 WINDOW w AS (
     ORDER BY id
     ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
-    INITIAL
     AFTER MATCH SKIP TO NEXT ROW
+    INITIAL
     PATTERN (A+)
     DEFINE
         A AS 'A' = ANY(flags)
@@ -2581,7 +2579,7 @@ WINDOW w AS (
         A AS 'A' = ANY(flags)
 );
 
--- Mode difference verification (INITIAL not yet supported - produces syntax error)
+-- Mode equivalence verification: explicit INITIAL equals the default mode
 WITH test_mode_diff AS (
     SELECT * FROM (VALUES
         (1, ARRAY['_']),
@@ -2595,8 +2593,8 @@ FROM (
     WINDOW w AS (
         ORDER BY id
         ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
-        INITIAL
         AFTER MATCH SKIP TO NEXT ROW
+        INITIAL
         PATTERN (A)
         DEFINE A AS 'A' = ANY(flags)
     )
-- 
2.50.1 (Apple Git-155)