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: Make some minor improvements in the regex code.
Date: Wed, 17 Feb 2021 17:24:53 +0000
Message-ID: <E1lCQZJ-0003gH-8o@gemulon.postgresql.org> (raw)

Make some minor improvements in the regex code.

Push some hopefully-uncontroversial bits extracted from an upcoming
patch series, to remove non-relevant clutter from the main patches.

In compact(), return immediately after setting REG_ASSERT error;
continuing the loop would just lead to assertion failure below.
(Ask me how I know.)

In parseqatom(), remove assertion that moresubs() did its job.
When moresubs actually did its job, this is redundant with that
function's final assert; but when it failed on OOM, this is an
assertion crash.  We could avoid the crash by adding a NOERR()
check before the assertion, but it seems better to subtract code
than add it.  (Note that there's a NOERR exit a few lines further
down, and nothing else between here and there requires moresubs
to have succeeded.  So we don't really need an extra error exit.)
This is a live bug in assert-enabled builds, but given the very
low likelihood of OOM in moresub's tiny allocation, I don't think
it's worth back-patching.

On the other hand, it seems worthwhile to add an assertion that
our intended v->subs[subno] target is still null by the time we
are ready to insert into it, since there's a recursion in between.

In pg_regexec, ensure we fflush any debug output on the way out,
and try to make MDEBUG messages more uniform and helpful.  (In
particular, ensure that all of them are prefixed with the subre's
id number, so one can match up entry and exit reports.)

Add some test cases in test_regex to improve coverage of lookahead
and lookbehind constraints.  Adding these now is mainly to establish
that this is indeed the existing behavior.

Discussion: https://postgr.es/m/1340281.1613018383@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4e703d67193df0431c0740044d662d1feade73aa

Modified Files
--------------
src/backend/regex/regc_nfa.c                       |  2 +-
src/backend/regex/regcomp.c                        |  2 +-
src/backend/regex/regexec.c                        | 61 +++++++++++++---------
.../modules/test_regex/expected/test_regex.out     | 48 +++++++++++++++++
src/test/modules/test_regex/sql/test_regex.sql     | 13 +++++
5 files changed, 99 insertions(+), 27 deletions(-)



Message-ID: <E1lCQZJ-0003gH-8o@gemulon.postgresql.org>
Permalink:  ../E1lCQZJ-0003gH-8o@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lCQZJ-0003gH-8o@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: Make some minor improvements in the regex code.
  In-Reply-To: <E1lCQZJ-0003gH-8o@gemulon.postgresql.org>
  References: <E1lCQZJ-0003gH-8o@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