pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Let regexp_replace() make use of REG_NOSUB when feasible.
Date: Tue, 10 Aug 2021 00:53:39 +0000
Message-ID: <E1mDG1T-0001fE-Ny@gemulon.postgresql.org> (raw)

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(-)



Message-ID: <E1mDG1T-0001fE-Ny@gemulon.postgresql.org>
Permalink:  ../E1mDG1T-0001fE-Ny@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1mDG1T-0001fE-Ny@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Let regexp_replace() make use of REG_NOSUB when feasible.
  In-Reply-To: <E1mDG1T-0001fE-Ny@gemulon.postgresql.org>
  References: <E1mDG1T-0001fE-Ny@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox