]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Let regexp_replace() make use of REG_NOSUB when feasible.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 10 Aug 2021 00:53:25 +0000 (20:53 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 10 Aug 2021 00:53:25 +0000 (20:53 -0400)
commit18bac60ede44359a1e577df80aef196e371c902e
treee9266d8ac6837c51f88abbe5b379c2ea5d708b68
parente12694523e7e4482a052236f12d3d8b58be9a22c
Let regexp_replace() make use of REG_NOSUB when feasible.

If the replacement string doesn't contain \1...\9, then we don't
need sub-match locations, so we can use the REG_NOSUB optimization
here too.  There's already a pre-scan of the replacement string
to look for backslashes, so extend that to check for digits, and
refactor to allow that to happen before we compile the regexp.

While at it, try to speed up the pre-scan by using memchr() instead
of a handwritten loop.  It's likely that this is lost in the noise
compared to the regexp processing proper, but maybe not.  In any
case, this coding is shorter.

Also, add some test cases to improve the poor coverage of
appendStringInfoRegexpSubstr().

Discussion: https://postgr.es/m/3534632.1628536485@sss.pgh.pa.us
src/backend/utils/adt/regexp.c
src/backend/utils/adt/varlena.c
src/include/utils/varlena.h
src/test/regress/expected/strings.out
src/test/regress/sql/strings.sql