Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: "Daniel Verite" <daniel(at)manitou-mail(dot)org>, "Robert Schreiber" <bobschreiber(at)charter(dot)net>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug
Date: 2019-05-12 16:55:47
Message-ID: 20583.1557680147@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Tom> Huh, interesting. So we should be translating the initial
> Tom> substring to a non-greedy pattern. I believe Spencer's engine can
> Tom> handle that by sticking (?:...){1,1}? around it.

> Your suggested fix doesn't seem to work. If the leading/trailing
> substrings do not have | or parens in then it seems to work to wrap them
> in (?:(?:)??...), thanks to the rule that the first quantified atom in a
> subexpression sets the whole subexpression's greediness, but handling |
> or parens correctly seems harder.

[ pokes at that... ] Huh. That's a bug, which AFAICS is aboriginal in
Henry's code: it optimizes away a {1,1} quantifier without regard to
whether the quantifier is attempting to impose a different greediness
preference than its argument would have naturally. The attached
seems to fix it.

regards, tom lane

Attachment Content-Type Size
fix-regex-greediness-imposition.patch text/x-diff 3.1 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Langote 2019-05-13 05:40:38 Re: inconsistent results querying table partitioned by date
Previous Message Andrew Gierth 2019-05-12 04:27:48 Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug