Re: Some regular-expression performance hacking

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chapman Flack <chap@anastigmatix.net>
Cc: Joel Jacobson <joel@compiler.org>, pgsql-hackers@lists.postgresql.org
Date: 2021-02-21T01:13:29Z
Lists: pgsql-hackers
Chapman Flack <chap@anastigmatix.net> writes:
> On 02/19/21 10:26, Tom Lane wrote:
>> Oooh, that's very interesting.   I guess the advantage of that over using
>> the 's' flag is that you can have different behaviors at different places
>> in the same regex.

> Perl, Python, and Java (at least) all have a common syntax for changing
> flags locally in a non-capturing group, so you could just match (?s:.)
> -- which I guess isn't any shorter than [\w\W] but makes the intent more
> clear.

Hmm, interesting.

> I see that JavaScript, for some reason, does not advertise that. We don't
> either; we have (?:groups) without flags, and we have (?flags) but only
> global at the start of the regex. Would it be worthwhile to jump on the
> bandwagon and support local flags in groups?

Yeah, perhaps.  Not sure whether there are any built-in assumptions about
these flags holding still throughout the regex; that'd require some
review.  But it seems like it could be a useful feature, and I don't
see any argument why we shouldn't have it.

			regards, tom lane



Commits

  1. Suppress unnecessary regex subre nodes in a couple more cases.

  2. Improve memory management in regex compiler.

  3. Extend a test case a little

  4. Allow complemented character class escapes within regex brackets.

  5. Suppress compiler warning in new regex match-all detection code.

  6. Avoid generating extra subre tree nodes for capturing parentheses.

  7. Convert regex engine's subre tree from binary to N-ary style.

  8. Fix regex engine to suppress useless concatenation sub-REs.

  9. Recognize "match-all" NFAs within the regex engine.

  10. Invent "rainbow" arcs within the regex engine.

  11. Make some minor improvements in the regex code.

  12. Display the time when the process started waiting for the lock, in pg_locks, take 2

  13. README/C-comment: document GiST's NSN value

  14. doc: Mention NO DEPENDS ON EXTENSION in its supported ALTER commands