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: Convert regex engine's subre tree from binary to N-ary style.
Date: Sun, 21 Feb 2021 00:26:59 +0000
Message-ID: <E1lDcaR-0004ib-I4@gemulon.postgresql.org> (raw)

Convert regex engine's subre tree from binary to N-ary style.

Instead of having left and right child links in subre structs,
have a single child link plus a sibling link.  Multiple children
of a tree node are now reached by chasing the sibling chain.

The beneficiary of this is alternation tree nodes.  A regular
expression with N (>1) branches is now represented by one alternation
node with N children, rather than a tree that includes N alternation
nodes as well as N children.  While the old representation didn't
really cost anything extra at execution time, it was pretty horrid
for compilation purposes, because each of the alternation nodes had
its own NFA, which we were too stupid not to separately optimize.
(To make matters worse, all of those NFAs described the entire
alternation pattern, not just the portion of it that one might
expect from the tree structure.)

We continue to require concatenation nodes to have exactly two
children.  This data structure is now prepared to support more,
but the executor's logic would need some careful redesign, and
it's not clear that a lot of benefit could be had.

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/581043089472816061a7fd381f40572191dfa48f

Modified Files
--------------
src/backend/regex/README    |   4 +-
src/backend/regex/regcomp.c | 222 +++++++++++++++++++++++---------------------
src/backend/regex/regexec.c | 104 +++++++++++----------
src/include/regex/regguts.h |  20 ++--
4 files changed, 185 insertions(+), 165 deletions(-)



Message-ID: <E1lDcaR-0004ib-I4@gemulon.postgresql.org>
Permalink:  ../E1lDcaR-0004ib-I4@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lDcaR-0004ib-I4@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: Convert regex engine's subre tree from binary to N-ary style.
  In-Reply-To: <E1lDcaR-0004ib-I4@gemulon.postgresql.org>
  References: <E1lDcaR-0004ib-I4@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