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: Improve regex compiler's arc moving/copying logic.
Date: Tue, 17 Aug 2021 16:00:12 +0000
Message-ID: <E1mG1Vc-0000ph-Q9@gemulon.postgresql.org> (raw)

Improve regex compiler's arc moving/copying logic.

The functions moveins(), copyins(), moveouts(), copyouts() are
required to preserve the invariant that there are no duplicate arcs in
the regex's NFA.  Spencer's original implementation of them was O(N^2)
since it checked separately for a match to each source arc.  In commit
579840ca0 I improved that by adding sort/merge logic to be used if
more than a few arcs are to be moved/copied.  However, I now realize
that that missed a bet.  At many call sites, the target state is newly
made and cannot have any existing in-arcs (respectively out-arcs)
that could be duplicates.  So spending any cycles at all on checking
for duplicates is wasted effort; in these cases we can just blindly
move/copy all the source arcs.  Add code paths to do that.

It turns out that for copyins()/copyouts(), *all* the call sites have
this property, making all the "improved" logic in them flat out
unreachable.  Perhaps we'll need the full capability again someday,
so I just #ifdef'd those paths out rather than removing them entirely.

In passing, add a few test cases to improve code coverage in this
area as well as in regc_locale.c/regc_pg_locale.c.

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/78a843f119ca7d4a6eb173a7ee3bed45889d48d8

Modified Files
--------------
src/backend/regex/regc_nfa.c                       |  66 +++++++++++-
.../modules/test_regex/expected/test_regex.out     | 120 +++++++++++++++++++++
.../test_regex/expected/test_regex_utf8.out        | 106 ++++++++++++++++++
src/test/modules/test_regex/sql/test_regex.sql     |  32 ++++++
.../modules/test_regex/sql/test_regex_utf8.sql     |  18 ++++
5 files changed, 338 insertions(+), 4 deletions(-)



Message-ID: <E1mG1Vc-0000ph-Q9@gemulon.postgresql.org>
Permalink:  ../E1mG1Vc-0000ph-Q9@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1mG1Vc-0000ph-Q9@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: Improve regex compiler's arc moving/copying logic.
  In-Reply-To: <E1mG1Vc-0000ph-Q9@gemulon.postgresql.org>
  References: <E1mG1Vc-0000ph-Q9@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