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: Invent "rainbow" arcs within the regex engine.
Date: Sun, 21 Feb 2021 00:26:59 +0000
Message-ID: <E1lDcaR-0004iU-Gn@gemulon.postgresql.org> (raw)

Invent "rainbow" arcs within the regex engine.

Some regular expression constructs, most notably the "." match-anything
metacharacter, produce a sheaf of parallel NFA arcs covering all
possible colors (that is, character equivalence classes).  We can make
a noticeable improvement in the space and time needed to process large
regexes by replacing such cases with a single arc bearing the special
color code "RAINBOW".  This requires only minor additional complication
in places such as pull() and push().

Callers of pg_reg_getoutarcs() must now be prepared for the possibility
of seeing a RAINBOW arc.  For the one known user, contrib/pg_trgm,
that's a net benefit since it cuts the number of arcs to be dealt with,
and the handling isn't any different than for other colors that contain
too many characters to be dealt with individually.

This is part of a patch series that in total reduces the regex engine's
runtime by about a factor of four on a large corpus of real-world regexes.

Patch by me, reviewed by Joel Jacobson

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/08c0d6ad65f7c161add82ae906efb90dbd7f653d

Modified Files
--------------
contrib/pg_trgm/trgm_regexp.c  | 27 +++++++++-----
src/backend/regex/README       | 36 ++++++++++++++-----
src/backend/regex/regc_color.c | 22 +++++++++++-
src/backend/regex/regc_nfa.c   | 82 +++++++++++++++++++++++++++++++++++++-----
src/backend/regex/regcomp.c    | 12 ++++---
src/backend/regex/rege_dfa.c   |  5 ++-
src/backend/regex/regexport.c  |  7 ++--
src/backend/regex/regprefix.c  |  8 +++--
src/include/regex/regexport.h  |  4 +++
src/include/regex/regguts.h    | 11 +++++-
10 files changed, 177 insertions(+), 37 deletions(-)



Message-ID: <E1lDcaR-0004iU-Gn@gemulon.postgresql.org>
Permalink:  ../E1lDcaR-0004iU-Gn@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lDcaR-0004iU-Gn@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: Invent "rainbow" arcs within the regex engine.
  In-Reply-To: <E1lDcaR-0004iU-Gn@gemulon.postgresql.org>
  References: <E1lDcaR-0004iU-Gn@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