Re: Another regexp performance improvement: skip useless paren-captures
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mark Dilger <mark.dilger@enterprisedb.com>
Cc: Andrew Dunstan <andrew@dunslane.net>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Joel Jacobson <joel@compiler.org>
Date: 2021-08-09T19:14:45Z
Lists: pgsql-hackers
Attachments
- let-regexp_replace-use-NOSUB.patch (text/x-diff) patch
Mark Dilger <mark.dilger@enterprisedb.com> writes: > The patch looks ready to commit. I don't expect to test it any further unless you have something in particular you'd like me to focus on. Pushed, but while re-reading it before commit I noticed that there's some more fairly low-hanging fruit in regexp_replace(). As I had it in that patch, it never used REG_NOSUB because of the possibility that the replacement string uses "\N". However, we're already pre-checking the replacement string to see if it has backslashes at all, so while we're at it we can check for \N to discover if we actually need any subexpression match data or not. We do need to refactor a little to postpone calling pg_regcomp until after we know that, but I think that makes replace_text_regexp's API less ugly not more so. While I was at it, I changed the search-for-backslash loops to use memchr rather than handwritten looping. Their use of pg_mblen was pretty unnecessary given we only need to find backslashes, and we can assume the backend encoding is ASCII-safe. Using a bunch of random cases generated by your little perl script, I see maybe 10-15% speedup on test cases that don't use \N in the replacement string, while it's about a wash on cases that do. (If I'd been using a multibyte encoding, maybe the memchr change would have made a difference, but I didn't try that.) regards, tom lane
Commits
-
Fix regexp misbehavior with capturing parens inside "{0}".
- 92620e82f6a1 12.9 landed
- 7e75fe390b68 9.6.24 landed
- 3ebd32e70c09 11.14 landed
- 244dd79923a1 14.0 landed
- 071146184a59 13.5 landed
- 062c4c791937 10.19 landed
- 65dc30ced64c 15.0 landed
-
Let regexp_replace() make use of REG_NOSUB when feasible.
- 18bac60ede44 15.0 landed
-
Fix bogus assertion in BootstrapModeMain().
- e12694523e7e 15.0 cited
-
Avoid determining regexp subexpression matches, when possible.
- 0e6aa8747d43 15.0 landed
-
Check the size in COPY_POINTER_FIELD
- c1132aae336c 15.0 cited
-
Make regexp engine's backref-related compilation state more bulletproof.
- cb76fbd7ec87 15.0 cited