From 7279cdc16c6571c5995bd926351e81c92205978f Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Wed, 10 Jun 2026 16:41:45 +0900 Subject: [PATCH 72/77] Remove the unused reluctant_location field from RPRPatternNode The reluctant_location field was only ever written and copied, never read to produce an error cursor or any other output, so drop it from RPRPatternNode. With it gone, makeRPRQuantifier no longer needs the reluctant_location argument (it now takes a plain bool reluctant) nor the core_yyscan_t yyscanner argument, which was already unused. Update the gram.y call sites and the README.rpr field list to match. No behavior change. --- src/backend/executor/README.rpr | 2 - src/backend/optimizer/plan/rpr.c | 4 -- src/backend/parser/gram.y | 71 ++++++++++++++------------------ src/include/nodes/parsenodes.h | 1 - 4 files changed, 31 insertions(+), 47 deletions(-) diff --git a/src/backend/executor/README.rpr b/src/backend/executor/README.rpr index 56ba8550c9c..00af86681b8 100644 --- a/src/backend/executor/README.rpr +++ b/src/backend/executor/README.rpr @@ -156,8 +156,6 @@ All nodes have min/max fields to express quantifiers: A{3,5} -> VAR(A, min=3, max=5) If the reluctant field is true, the quantifier is reluctant (non-greedy). -(RPRPatternNode.reluctant is bool; reluctant_location is the separate -ParseLoc field holding the '?' token position, or -1 if absent.) Example: PATTERN ((A+ B) | C*) diff --git a/src/backend/optimizer/plan/rpr.c b/src/backend/optimizer/plan/rpr.c index a38eb2fd4f0..09445391e8c 100644 --- a/src/backend/optimizer/plan/rpr.c +++ b/src/backend/optimizer/plan/rpr.c @@ -405,7 +405,6 @@ mergeConsecutiveAlts(List *children) group->min = count; group->max = count; group->reluctant = false; - group->reluctant_location = -1; group->location = -1; group->children = list_make1(prev); mergedChildren = lappend(mergedChildren, group); @@ -430,7 +429,6 @@ mergeConsecutiveAlts(List *children) group->min = count; group->max = count; group->reluctant = false; - group->reluctant_location = -1; group->location = -1; group->children = list_make1(prev); mergedChildren = lappend(mergedChildren, group); @@ -455,7 +453,6 @@ mergeConsecutiveAlts(List *children) group->min = count; group->max = count; group->reluctant = false; - group->reluctant_location = -1; group->location = -1; group->children = list_make1(prev); mergedChildren = lappend(mergedChildren, group); @@ -906,7 +903,6 @@ tryUnwrapGroup(RPRPatternNode *pattern) child->min = pattern->min; child->max = pattern->max; child->reluctant = pattern->reluctant; - child->reluctant_location = pattern->reluctant_location; return child; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index ac2e5d7914a..1a5459fa150 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -212,8 +212,8 @@ static void preprocess_pubobj_list(List *pubobjspec_list, static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); static RPRPatternNode *makeRPRSeqOrSingle(List *children, int location); static RPRPatternNode *splitRPRTrailingAlt(RPRPatternNode *node, core_yyscan_t yyscanner); -static RPRPatternNode *makeRPRQuantifier(int32 min, int32 max, ParseLoc reluctant, int location, - core_yyscan_t yyscanner); +static RPRPatternNode *makeRPRQuantifier(int32 min, int32 max, bool reluctant, + int location); %} @@ -17653,7 +17653,6 @@ row_pattern_alt: n->min = 1; n->max = 1; n->reluctant = false; - n->reluctant_location = -1; n->location = @1; $$ = (Node *) n; } @@ -17686,7 +17685,6 @@ row_pattern_seq: n->min = 1; n->max = 1; n->reluctant = false; - n->reluctant_location = -1; n->location = @1; $$ = (Node *) n; } @@ -17702,7 +17700,6 @@ row_pattern_term: n->min = q->min; n->max = q->max; n->reluctant = q->reluctant; - n->reluctant_location = q->reluctant_location; n->trailing_alt = q->trailing_alt; $$ = (Node *) n; } @@ -17717,7 +17714,6 @@ row_pattern_primary: n->min = 1; n->max = 1; n->reluctant = false; - n->reluctant_location = -1; n->children = NIL; n->location = @1; $$ = (Node *) n; @@ -17731,7 +17727,6 @@ row_pattern_primary: n->min = 1; n->max = 1; n->reluctant = false; - n->reluctant_location = -1; n->location = @1; $$ = (Node *) n; } @@ -17741,55 +17736,55 @@ row_pattern_quantifier_opt: /* EMPTY - no quantifier means exactly once; @$ is unused since * min=max=1 never produces an error */ { - $$ = (Node *) makeRPRQuantifier(1, 1, -1, @$, yyscanner); + $$ = (Node *) makeRPRQuantifier(1, 1, false, @$); } | '*' { - $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, false, @1); } | '+' { - $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, false, @1); } | Op { /* Handle single Op: ? or reluctant quantifiers *?, +?, ?? */ if (strcmp($1, "?") == 0) - $$ = (Node *) makeRPRQuantifier(0, 1, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, 1, false, @1); else if (strcmp($1, "*?") == 0) - $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, @1 + 1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, true, @1); else if (strcmp($1, "+?") == 0) - $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, @1 + 1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, true, @1); else if (strcmp($1, "??") == 0) - $$ = (Node *) makeRPRQuantifier(0, 1, @1 + 1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, 1, true, @1); else if (strcmp($1, "*|") == 0) { - $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, false, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else if (strcmp($1, "+|") == 0) { - $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, false, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else if (strcmp($1, "?|") == 0) { - $$ = (Node *) makeRPRQuantifier(0, 1, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, 1, false, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else if (strcmp($1, "*?|") == 0) { - $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, @1 + 1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, true, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else if (strcmp($1, "+?|") == 0) { - $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, @1 + 1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, true, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else if (strcmp($1, "??|") == 0) { - $$ = (Node *) makeRPRQuantifier(0, 1, @1 + 1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, 1, true, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else @@ -17803,11 +17798,11 @@ row_pattern_quantifier_opt: | '*' Op { if (strcmp($2, "?") == 0) - $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, @2, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, true, @1); else if (strcmp($2, "?|") == 0) { /* "A* ?|B" = reluctant "A*?" plus alternation */ - $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, @2, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, PG_INT32_MAX, true, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else @@ -17820,11 +17815,11 @@ row_pattern_quantifier_opt: | '+' Op { if (strcmp($2, "?") == 0) - $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, @2, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, true, @1); else if (strcmp($2, "?|") == 0) { /* "A+ ?|B" = reluctant "A+?" plus alternation */ - $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, @2, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(1, PG_INT32_MAX, true, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else @@ -17843,11 +17838,11 @@ row_pattern_quantifier_opt: errhint("Did you mean \"??\" for reluctant quantifier?"), parser_errposition(@1)); if (strcmp($2, "?") == 0) - $$ = (Node *) makeRPRQuantifier(0, 1, @2, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, 1, true, @1); else if (strcmp($2, "?|") == 0) { /* "A? ?|B" = reluctant "A??" plus alternation */ - $$ = (Node *) makeRPRQuantifier(0, 1, @2, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, 1, true, @1); ((RPRPatternNode *) $$)->trailing_alt = true; } else @@ -17865,7 +17860,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier bound must be between 1 and %d", PG_INT32_MAX - 1), parser_errposition(@2)); - $$ = (Node *) makeRPRQuantifier($2, $2, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier($2, $2, false, @1); } | '{' Iconst ',' '}' { @@ -17874,7 +17869,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier bound must be between 0 and %d", PG_INT32_MAX - 1), parser_errposition(@2)); - $$ = (Node *) makeRPRQuantifier($2, PG_INT32_MAX, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier($2, PG_INT32_MAX, false, @1); } | '{' ',' Iconst '}' { @@ -17883,7 +17878,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier bound must be between 1 and %d", PG_INT32_MAX - 1), parser_errposition(@3)); - $$ = (Node *) makeRPRQuantifier(0, $3, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, $3, false, @1); } | '{' Iconst ',' Iconst '}' { @@ -17897,7 +17892,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier minimum bound must not exceed maximum"), parser_errposition(@2)); - $$ = (Node *) makeRPRQuantifier($2, $4, -1, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier($2, $4, false, @1); } /* Reluctant versions: {n}?, {n,}?, {,m}?, {n,m}? */ | '{' Iconst '}' Op @@ -17913,7 +17908,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier bound must be between 1 and %d", PG_INT32_MAX - 1), parser_errposition(@2)); - $$ = (Node *) makeRPRQuantifier($2, $2, @4, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier($2, $2, true, @1); if (strcmp($4, "?|") == 0) ((RPRPatternNode *) $$)->trailing_alt = true; } @@ -17930,7 +17925,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier bound must be between 0 and %d", PG_INT32_MAX - 1), parser_errposition(@2)); - $$ = (Node *) makeRPRQuantifier($2, PG_INT32_MAX, @5, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier($2, PG_INT32_MAX, true, @1); if (strcmp($5, "?|") == 0) ((RPRPatternNode *) $$)->trailing_alt = true; } @@ -17947,7 +17942,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier bound must be between 1 and %d", PG_INT32_MAX - 1), parser_errposition(@3)); - $$ = (Node *) makeRPRQuantifier(0, $3, @5, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier(0, $3, true, @1); if (strcmp($5, "?|") == 0) ((RPRPatternNode *) $$)->trailing_alt = true; } @@ -17969,7 +17964,7 @@ row_pattern_quantifier_opt: errcode(ERRCODE_SYNTAX_ERROR), errmsg("quantifier minimum bound must not exceed maximum"), parser_errposition(@2)); - $$ = (Node *) makeRPRQuantifier($2, $4, @6, @1, yyscanner); + $$ = (Node *) makeRPRQuantifier($2, $4, true, @1); if (strcmp($6, "?|") == 0) ((RPRPatternNode *) $$)->trailing_alt = true; } @@ -21400,15 +21395,13 @@ makeRecursiveViewSelect(char *relname, List *aliases, Node *query) * Create an RPRPatternNode with specified quantifier bounds. */ static RPRPatternNode * -makeRPRQuantifier(int32 min, int32 max, ParseLoc reluctant_location, int location, - core_yyscan_t yyscanner) +makeRPRQuantifier(int32 min, int32 max, bool reluctant, int location) { RPRPatternNode *n = makeNode(RPRPatternNode); n->min = min; n->max = max; - n->reluctant = (reluctant_location >= 0); - n->reluctant_location = reluctant_location; + n->reluctant = reluctant; n->location = location; return n; } @@ -21430,7 +21423,6 @@ makeRPRSeqOrSingle(List *children, int location) n->min = 1; n->max = 1; n->reluctant = false; - n->reluctant_location = -1; n->location = location; return n; } @@ -21491,7 +21483,6 @@ splitRPRTrailingAlt(RPRPatternNode *node, core_yyscan_t yyscanner) altn->min = 1; altn->max = 1; altn->reluctant = false; - altn->reluctant_location = -1; altn->location = node->location; return altn; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 16f31dbe7ff..04282811717 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -628,7 +628,6 @@ typedef struct RPRPatternNode int32 min; /* minimum repetitions (0 for *, ?) */ int32 max; /* maximum repetitions (PG_INT32_MAX for *, +) */ bool reluctant; /* true for reluctant (non-greedy) */ - ParseLoc reluctant_location; /* location of '?' token, or -1 */ ParseLoc location; /* token location, or -1 */ char *varName; /* VAR: variable name */ List *children; /* SEQ, ALT, GROUP: child nodes */ -- 2.50.1 (Apple Git-155)