pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Dilger <mark.dilger@enterprisedb.com>
To: Miles Elam <miles.elam@productops.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: [E] Regexp_replace bug / does not terminate on long strings
Date: Fri, 20 Aug 2021 13:26:37 -0700
Message-ID: <060D9E3A-C827-4EDD-AFB7-C70EF5DCD186@enterprisedb.com> (raw)
In-Reply-To: <CAALojA-uQ+C_SOa2tfX3-sZypVZJJasxaOS2JLbgPDoGaMtFGQ@mail.gmail.com>
References: <CALZg0g4FA1Xc5UMLrGBKM--erUGEAhe8GGLE-YcN7=O6rw2=0A@mail.gmail.com>
	<1809528.1629412955@sss.pgh.pa.us>
	<CALZg0g4T5u+9DUomsuN913MK_TS1GZM=8pMuJR+j=-0yiQdJrQ@mail.gmail.com>
	<1917678.1629478364@sss.pgh.pa.us>
	<D84B8669-286F-4F90-89D6-6566D93C2C08@enterprisedb.com>
	<CAALojA-uQ+C_SOa2tfX3-sZypVZJJasxaOS2JLbgPDoGaMtFGQ@mail.gmail.com>



> On Aug 20, 2021, at 12:51 PM, Miles Elam <miles.elam@productops.com> wrote:
> 
> Unbounded ranges seem like a problem.

Seems so.  The problem appears to be in regcomp.c's repeat() function which handles {1,SOME} differently than {1,INF}

> Seems worth trying a range from 1 to N where you play around with N to find your optimum performance/functionality tradeoff. {1,20} is like '+' but clamps at 20.

For any such value (5, 20, whatever) there can always be a string with more repeated words than the number you've chosen, and the call to regexp_replace won't do what you want.  There is also an upper bound at work, because values above 255 will draw a regex compilation error.  So it seems worth a bit of work to determine why the regex engine has bad performance in these cases.

It sounds like the OP will be working around this problem by refactoring to call regexp_replace multiple times until all repeats are eradicated, but I don't think such workarounds should be necessary.

—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company








view thread (14+ messages)  latest in thread

Message-ID: <060D9E3A-C827-4EDD-AFB7-C70EF5DCD186@enterprisedb.com>
Permalink:  ../060D9E3A-C827-4EDD-AFB7-C70EF5DCD186@enterprisedb.com/
Also on:    postgresql.org/message-id/060D9E3A-C827-4EDD-AFB7-C70EF5DCD186@enterprisedb.com

 · 

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-general@postgresql.org
  Cc: mark.dilger@enterprisedb.com, miles.elam@productops.com
  Subject: Re: [E] Regexp_replace bug / does not terminate on long strings
  In-Reply-To: <060D9E3A-C827-4EDD-AFB7-C70EF5DCD186@enterprisedb.com>
  References: <CALZg0g4FA1Xc5UMLrGBKM--erUGEAhe8GGLE-YcN7=O6rw2=0A@mail.gmail.com> <1809528.1629412955@sss.pgh.pa.us> <CALZg0g4T5u+9DUomsuN913MK_TS1GZM=8pMuJR+j=-0yiQdJrQ@mail.gmail.com> <1917678.1629478364@sss.pgh.pa.us> <D84B8669-286F-4F90-89D6-6566D93C2C08@enterprisedb.com> <CAALojA-uQ+C_SOa2tfX3-sZypVZJJasxaOS2JLbgPDoGaMtFGQ@mail.gmail.com> <060D9E3A-C827-4EDD-AFB7-C70EF5DCD186@enterprisedb.com>

* 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