pgsql: Make some minor improvements in the regex code. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Make some minor improvements in the regex code.
Date
Msg-id E1lCQZJ-0003gH-8o@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Routine usage information schema tables
Next
From: Tomas Vondra
Date:
Subject: pgsql: Fix tuple routing to initialize batching only for inserts