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: Avoid generating extra subre tree nodes for capturing parenthese
Date: Sun, 21 Feb 2021 00:26:59 +0000
Message-ID: <E1lDcaR-0004ie-IQ@gemulon.postgresql.org> (raw)

Avoid generating extra subre tree nodes for capturing parentheses.

Previously, each pair of capturing parentheses gave rise to a separate
subre tree node, whose only function was to identify that we ought to
capture the match details for this particular sub-expression.  In
most cases we don't really need that, since we can perfectly well
put a "capture this" annotation on the child node that does the real
matching work.  As with the two preceding commits, the main value
of this is to avoid generating and optimizing an NFA for a tree node
that's not really pulling its weight.

The chosen data representation only allows one capture annotation
per subre node.  In the legal-per-spec, but seemingly not very useful,
case where there are multiple capturing parens around the exact same
bit of the regex (i.e. "((xyz))"), wrap the child node in N-1 capture
nodes that act the same as before.  We could work harder at that but
I'll refrain, pending some evidence that such cases are worth troubling
over.

In passing, improve the comments in regex.h to say what all the
different re_info bits mean.  Some of them were pretty obvious
but others not so much, so reverse-engineer some documentation.

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/ea1268f6301cc7adce571cc9c5ebe8d9342a2ef4

Modified Files
--------------
src/backend/regex/README     | 15 ++++++++++--
src/backend/regex/regcomp.c  | 54 ++++++++++++++++++++++++++++++++------------
src/backend/regex/rege_dfa.c |  6 ++---
src/backend/regex/regexec.c  | 22 ++++++++++--------
src/include/regex/regex.h    | 32 ++++++++++++++------------
src/include/regex/regguts.h  | 13 ++++++-----
6 files changed, 91 insertions(+), 51 deletions(-)



Message-ID: <E1lDcaR-0004ie-IQ@gemulon.postgresql.org>
Permalink:  ../E1lDcaR-0004ie-IQ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lDcaR-0004ie-IQ@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: Avoid generating extra subre tree nodes for capturing parenthese
  In-Reply-To: <E1lDcaR-0004ie-IQ@gemulon.postgresql.org>
  References: <E1lDcaR-0004ie-IQ@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