nocfbot-0011-Clarify-excludeLocation-and-empty-quantifier.txt

text/plain

Filename: nocfbot-0011-Clarify-excludeLocation-and-empty-quantifier.txt
Type: text/plain
Part: 10
Message: Re: Row pattern recognition
From 7b9d7fb735a467ff391898ed4ebc11bd6ef315fa Mon Sep 17 00:00:00 2001
From: Henson Choi <assam258@gmail.com>
Date: Fri, 20 Mar 2026 21:21:58 +0900
Subject: [PATCH] Add clarifying comments for excludeLocation and empty
 quantifier in gram.y

Add comments explaining that excludeLocation is set to -1 when no
EXCLUDE clause is present (opt_window_exclusion_clause returns 0),
and that the EMPTY quantifier rule's @$ location is unused since
min=max=1 never produces an error.
---
 src/backend/parser/gram.y | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 9dcac63bdc7..6d390258532 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -16757,6 +16757,7 @@ opt_frame_clause:
 					n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
 					n->frameOptions |= $3;
 					n->frameLocation = @1;
+					/* -1 when no EXCLUDE clause (opt_window_exclusion_clause returns 0) */
 					n->excludeLocation = ($3 != 0) ? @3 : -1;
 					$$ = n;
 				}
@@ -16767,6 +16768,7 @@ opt_frame_clause:
 					n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
 					n->frameOptions |= $3;
 					n->frameLocation = @1;
+					/* -1 when no EXCLUDE clause (opt_window_exclusion_clause returns 0) */
 					n->excludeLocation = ($3 != 0) ? @3 : -1;
 					$$ = n;
 				}
@@ -16777,6 +16779,7 @@ opt_frame_clause:
 					n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
 					n->frameOptions |= $3;
 					n->frameLocation = @1;
+					/* -1 when no EXCLUDE clause (opt_window_exclusion_clause returns 0) */
 					n->excludeLocation = ($3 != 0) ? @3 : -1;
 					$$ = n;
 				}
@@ -17069,7 +17072,9 @@ row_pattern_primary:
 		;
 
 row_pattern_quantifier_opt:
-			/* EMPTY */				{ $$ = (Node *) makeRPRQuantifier(1, 1, -1, @$, yyscanner); }
+			/* EMPTY - no quantifier means exactly once; @$ is unused since
+			 * min=max=1 never produces an error */
+			{ $$ = (Node *) makeRPRQuantifier(1, 1, -1, @$, yyscanner); }
 			| '*'					{ $$ = (Node *) makeRPRQuantifier(0, INT_MAX, -1, @1, yyscanner); }
 			| '+'					{ $$ = (Node *) makeRPRQuantifier(1, INT_MAX, -1, @1, yyscanner); }
 			| Op
-- 
2.50.1 (Apple Git-155)