pgsql: Let regexp_replace() make use of REG_NOSUB when feasible.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Let regexp_replace() make use of REG_NOSUB when feasible.
Date: 2021-08-10 00:53:39
Message-ID: E1mDG1T-0001fE-Ny@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/18bac60ede44359a1e577df80aef196e371c902e

Modified Files
--------------
src/backend/utils/adt/regexp.c | 23 +++-----
src/backend/utils/adt/varlena.c | 101 ++++++++++++++++++----------------
src/include/utils/varlena.h | 3 +-
src/test/regress/expected/strings.out | 21 ++++++-
src/test/regress/sql/strings.sql | 7 ++-
5 files changed, 90 insertions(+), 65 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2021-08-10 03:22:49 pgsql: Add call to object access hook at the end of table rewrite in AL
Previous Message Tom Lane 2021-08-09 20:56:59 pgsql: Stamp 9.6.23.