nocfbot-0047-Update-the-varId-documentation-for-row-pattern-re.txt

text/plain

Filename: nocfbot-0047-Update-the-varId-documentation-for-row-pattern-re.txt
Type: text/plain
Part: 46
Message: Re: Row pattern recognition
From 04f18c586669af22eef26eab7f7cb383f0ccf6d4 Mon Sep 17 00:00:00 2001
From: Henson Choi <assam258@gmail.com>
Date: Fri, 5 Jun 2026 12:45:09 +0900
Subject: [PATCH 47/68] Update the varId documentation for row pattern
 recognition

Reserving the whole high varId nibble (0xF0-0xFF) for control elements
left 240 pattern variables (0x00-0xEF), but the documentation still
described the old 0-250 / 252-255 layout.

Update README.rpr's element table and control-code list to the hex
nibble boundaries, note the 0xF0-0xFB spare range, and correct the
user-facing limit in select.sgml from 251 to 240 unique pattern
variables.

Documentation only.
---
 doc/src/sgml/ref/select.sgml    |  2 +-
 src/backend/executor/README.rpr | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml
index e4708331439..be5ed814853 100644
--- a/doc/src/sgml/ref/select.sgml
+++ b/doc/src/sgml/ref/select.sgml
@@ -1198,7 +1198,7 @@ DEFINE <replaceable class="parameter">definition_variable_name</replaceable> AS
 
    <para>
     Note that the maximum number of unique pattern variables
-    used in the <literal>PATTERN</literal> clause is 251.
+    used in the <literal>PATTERN</literal> clause is 240.
     If this limit is exceeded, an error will be raised.
     Additionally, the maximum nesting depth of pattern groups
     (parentheses) is 253 levels.
diff --git a/src/backend/executor/README.rpr b/src/backend/executor/README.rpr
index 3a215f2566b..55f899f7fef 100644
--- a/src/backend/executor/README.rpr
+++ b/src/backend/executor/README.rpr
@@ -246,7 +246,7 @@ RPRPatternElement struct (16 bytes):
 
   Field      Size     Description
   ---------------------------------------------------------
-  varId      1B      Variable ID (0-250) or control code (252-255)
+  varId      1B      Variable ID (0-0xEF) or control code (0xFC-0xFF)
   depth      1B      Group nesting depth
   flags      1B      Bit flags (see below)
   reserved   1B      Padding
@@ -255,12 +255,17 @@ RPRPatternElement struct (16 bytes):
   next       2B      Next element index (sequential flow)
   jump       2B      Branch target index (for ALT/GROUP)
 
+Pattern variables occupy varId 0 to RPR_VARID_MAX (0xEF) inclusive,
+giving 240 distinct variables.  Any varId with the high nibble set
+(0xF0-0xFF) is reserved for control elements; 0xF0-0xFB are currently
+spare.
+
 Control codes:
 
-  RPR_VARID_BEGIN (252)  Group start marker
-  RPR_VARID_END   (253)  Group end marker
-  RPR_VARID_ALT   (254)  Alternation start marker
-  RPR_VARID_FIN   (255)  Pattern completion marker
+  RPR_VARID_BEGIN (0xFC)  Group start marker
+  RPR_VARID_END   (0xFD)  Group end marker
+  RPR_VARID_ALT   (0xFE)  Alternation start marker
+  RPR_VARID_FIN   (0xFF)  Pattern completion marker
 
 Element flags (1 byte, bitmask):
 
-- 
2.50.1 (Apple Git-155)