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: Fix performance bug in regexp's citerdissect/creviterdissect.
Date: Fri, 20 Aug 2021 18:19:24 +0000
Message-ID: <E1mH96y-0006M1-Fr@gemulon.postgresql.org> (raw)

Fix performance bug in regexp's citerdissect/creviterdissect.

After detecting a sub-match "dissect" failure (i.e., a backref match
failure) in the i'th sub-match of an iteration node, we should proceed
by adjusting the attempted length of the i'th submatch.  As coded,
though, these functions changed the attempted length of the *last*
sub-match, and only after exhausting all possibilities for that would
they back up to adjust the next-to-last sub-match, and then the
second-from-last, etc; all of which is wasted effort, since only
changing the start or length of the i'th sub-match can possibly make
it succeed.  This oversight creates the possibility for exponentially
bad performance.  Fortunately the problem is masked in most cases by
optimizations or constraints applied elsewhere; which explains why
we'd not noticed it before.  But it is possible to reach the problem
with fairly simple, if contrived, regexps.

Oversight in my commit 173e29aa5.  That's pretty ancient now,
so back-patch to all supported branches.

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

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b30f7f399ea87f0621dfe900547cda401f8da762

Modified Files
--------------
src/backend/regex/regexec.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1mH96y-0006M1-Fr@gemulon.postgresql.org>
Permalink:  ../E1mH96y-0006M1-Fr@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1mH96y-0006M1-Fr@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: Fix performance bug in regexp's citerdissect/creviterdissect.
  In-Reply-To: <E1mH96y-0006M1-Fr@gemulon.postgresql.org>
  References: <E1mH96y-0006M1-Fr@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