diff options
| author | vvvv <[email protected]> | 2025-10-24 14:59:50 +0300 |
|---|---|---|
| committer | vvvv <[email protected]> | 2025-10-24 15:29:24 +0300 |
| commit | 5b0d18921f2a509d8363c40a5ca208dfed026287 (patch) | |
| tree | d1369c696d3a9e9a65b68d9208e198269a48cfbc /yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex | |
| parent | e7fbdb6e81ae4a296e710b133de7a2a04b31bbc4 (diff) | |
YQL-20567 upgrade PG up to 16.10 & fix instructions
init
commit_hash:81aba13295273281d19d2d332a48ff1c44977447
Diffstat (limited to 'yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex')
3 files changed, 60 insertions, 1 deletions
diff --git a/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_color.c b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_color.c index 30bda0e5ad0..8ae788f5195 100644 --- a/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_color.c +++ b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_color.c @@ -1075,9 +1075,19 @@ colorcomplement(struct nfa *nfa, assert(of != from); - /* A RAINBOW arc matches all colors, making the complement empty */ + /* + * A RAINBOW arc matches all colors, making the complement empty. But we + * can't just return without making any arcs, because that would leave the + * NFA disconnected which would break any future delsub(). Instead, make + * a CANTMATCH arc. Also set the HASCANTMATCH flag so we know we need to + * clean that up at the start of NFA optimization. + */ if (findarc(of, PLAIN, RAINBOW) != NULL) + { + newarc(nfa, CANTMATCH, 0, from, to); + nfa->flags |= HASCANTMATCH; return; + } /* Otherwise, transiently mark the colors that appear in of's out-arcs */ for (a = of->outs; a != NULL; a = a->outchain) @@ -1089,6 +1099,12 @@ colorcomplement(struct nfa *nfa, assert(!UNUSEDCOLOR(cd)); cd->flags |= COLMARK; } + + /* + * There's no syntax for re-complementing a color set, so we cannot + * see CANTMATCH arcs here. + */ + assert(a->type != CANTMATCH); } /* Scan colors, clear transient marks, add arcs for unmarked colors */ diff --git a/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_nfa.c b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_nfa.c index b60d5a3878e..bad9a8b36a1 100644 --- a/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_nfa.c +++ b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regc_nfa.c @@ -1407,6 +1407,7 @@ removetraverse(struct nfa *nfa, { case PLAIN: case EMPTY: + case CANTMATCH: /* nothing to do */ break; case AHEAD: @@ -1544,6 +1545,12 @@ optimize(struct nfa *nfa, if (verbose) fprintf(f, "\ninitial cleanup:\n"); #endif + /* If we have any CANTMATCH arcs, drop them; but this is uncommon */ + if (nfa->flags & HASCANTMATCH) + { + removecantmatch(nfa); + nfa->flags &= ~HASCANTMATCH; + } cleanup(nfa); /* may simplify situation */ #ifdef REG_DEBUG if (verbose) @@ -2866,6 +2873,34 @@ clonesuccessorstates(struct nfa *nfa, } /* + * removecantmatch - remove CANTMATCH arcs, which are no longer useful + * once we are done with the parsing phase. (We need them only to + * preserve connectedness of NFA subgraphs during parsing.) + */ +static void +removecantmatch(struct nfa *nfa) +{ + struct state *s; + + for (s = nfa->states; s != NULL; s = s->next) + { + struct arc *a; + struct arc *nexta; + + for (a = s->outs; a != NULL; a = nexta) + { + nexta = a->outchain; + if (a->type == CANTMATCH) + { + freearc(nfa, a); + if (NISERR()) + return; + } + } + } +} + +/* * cleanup - clean up NFA after optimizations */ static void @@ -3569,6 +3604,8 @@ dumpnfa(struct nfa *nfa, fprintf(f, ", eol [%ld]", (long) nfa->eos[1]); if (nfa->flags & HASLACONS) fprintf(f, ", haslacons"); + if (nfa->flags & HASCANTMATCH) + fprintf(f, ", hascantmatch"); if (nfa->flags & MATCHALL) { fprintf(f, ", minmatchall %d", nfa->minmatchall); @@ -3691,6 +3728,9 @@ dumparc(struct arc *a, break; case EMPTY: break; + case CANTMATCH: + fprintf(f, "X"); + break; default: fprintf(f, "0x%x/0%lo", a->type, (long) a->co); break; diff --git a/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regcomp.c b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regcomp.c index 8a6cfb2973d..15b264e50f1 100644 --- a/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regcomp.c +++ b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/regex/regcomp.c @@ -215,6 +215,7 @@ static void clonesuccessorstates(struct nfa *nfa, struct state *ssource, struct state *spredecessor, struct arc *refarc, char *curdonemap, char *outerdonemap, int nstates); +static void removecantmatch(struct nfa *nfa); static void cleanup(struct nfa *nfa); static void markreachable(struct nfa *nfa, struct state *s, struct state *okay, struct state *mark); @@ -342,6 +343,7 @@ struct vars #define BEHIND 'r' /* color-lookbehind arc */ #define WBDRY 'w' /* word boundary constraint */ #define NWBDRY 'W' /* non-word-boundary constraint */ +#define CANTMATCH 'x' /* arc that cannot match anything */ #define SBEGIN 'A' /* beginning of string (even if not BOL) */ #define SEND 'Z' /* end of string (even if not EOL) */ @@ -2368,6 +2370,7 @@ nfanode(struct vars *v, nfa = newnfa(v, v->cm, v->nfa); NOERRZ(); dupnfa(nfa, t->begin, t->end, nfa->init, nfa->final); + nfa->flags = v->nfa->flags; if (!ISERR()) specialcolors(nfa); if (!ISERR()) |
