diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-02-20 18:11:56 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-02-20 18:11:56 -0500 |
commit | 08c0d6ad65f7c161add82ae906efb90dbd7f653d (patch) | |
tree | cc6376d6fd084c6584b18d818c0816e3b7e190c9 /src/include/regex/regexport.h | |
parent | 17661188336c8cbb1783808912096932c57893a3 (diff) |
Invent "rainbow" arcs within the regex engine.
Some regular expression constructs, most notably the "." match-anything
metacharacter, produce a sheaf of parallel NFA arcs covering all
possible colors (that is, character equivalence classes). We can make
a noticeable improvement in the space and time needed to process large
regexes by replacing such cases with a single arc bearing the special
color code "RAINBOW". This requires only minor additional complication
in places such as pull() and push().
Callers of pg_reg_getoutarcs() must now be prepared for the possibility
of seeing a RAINBOW arc. For the one known user, contrib/pg_trgm,
that's a net benefit since it cuts the number of arcs to be dealt with,
and the handling isn't any different than for other colors that contain
too many characters to be dealt with individually.
This is part of a patch series that in total reduces the regex engine's
runtime by about a factor of four on a large corpus of real-world regexes.
Patch by me, reviewed by Joel Jacobson
Discussion: https://postgr.es/m/1340281.1613018383@sss.pgh.pa.us
Diffstat (limited to 'src/include/regex/regexport.h')
-rw-r--r-- | src/include/regex/regexport.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/include/regex/regexport.h b/src/include/regex/regexport.h index e6209463f7f..99c4fb854ec 100644 --- a/src/include/regex/regexport.h +++ b/src/include/regex/regexport.h @@ -30,6 +30,10 @@ #include "regex/regex.h" +/* These macros must match corresponding ones in regguts.h: */ +#define COLOR_WHITE 0 /* color for chars not appearing in regex */ +#define COLOR_RAINBOW (-2) /* represents all colors except pseudocolors */ + /* information about one arc of a regex's NFA */ typedef struct { |