pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression
6+ messages / 1 participants
[nested] [flat]
* pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression
@ 2019-05-12 22:54 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2019-05-12 22:54 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix misoptimization of "{1,1}" quantifiers in regular expressions.
A bounded quantifier with m = n = 1 might be thought a no-op. But
according to our documentation (which traces back to Henry Spencer's
original man page) it still imposes greediness, or non-greediness in the
case of the non-greedy variant "{1,1}?", on whatever it's attached to.
This turns out not to work though, because parseqatom() optimizes away
the m = n = 1 case without regard for whether it's supposed to change
the greediness of the argument RE.
We can fix this by just not applying the optimization when the greediness
needs to change; the subsequent general cases handle it fine.
The three cases in which we can still apply the optimization are
(a) no quantifier, or quantifier does not impose a preference;
(b) atom has no greediness property, implying it cannot match a
variable amount of text anyway; or
(c) quantifier's greediness is same as atom's.
Note that in most cases where one of these applies, we'd have exited
earlier in the "not a messy case" fast path. I think it's now only
possible to get to the optimization when the atom involves capturing
parentheses or a non-top-level backref.
Back-patch to all supported branches. I'd ordinarily be hesitant to
put a subtle behavioral change into back branches, but in this case
it's very hard to see a reason why somebody would write "{1,1}?" unless
they're trying to get the documented change-of-greediness behavior.
Discussion: https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/8a29ed05302ea18b4be177c2d1181b43706af45f
Modified Files
--------------
src/backend/regex/regcomp.c | 5 +++-
src/test/regress/expected/regex.out | 49 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/regex.sql | 10 ++++++++
3 files changed, 63 insertions(+), 1 deletion(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression
@ 2019-05-12 22:54 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2019-05-12 22:54 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix misoptimization of "{1,1}" quantifiers in regular expressions.
A bounded quantifier with m = n = 1 might be thought a no-op. But
according to our documentation (which traces back to Henry Spencer's
original man page) it still imposes greediness, or non-greediness in the
case of the non-greedy variant "{1,1}?", on whatever it's attached to.
This turns out not to work though, because parseqatom() optimizes away
the m = n = 1 case without regard for whether it's supposed to change
the greediness of the argument RE.
We can fix this by just not applying the optimization when the greediness
needs to change; the subsequent general cases handle it fine.
The three cases in which we can still apply the optimization are
(a) no quantifier, or quantifier does not impose a preference;
(b) atom has no greediness property, implying it cannot match a
variable amount of text anyway; or
(c) quantifier's greediness is same as atom's.
Note that in most cases where one of these applies, we'd have exited
earlier in the "not a messy case" fast path. I think it's now only
possible to get to the optimization when the atom involves capturing
parentheses or a non-top-level backref.
Back-patch to all supported branches. I'd ordinarily be hesitant to
put a subtle behavioral change into back branches, but in this case
it's very hard to see a reason why somebody would write "{1,1}?" unless
they're trying to get the documented change-of-greediness behavior.
Discussion: https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/72ce7acaf3e60da712f0de1916704a4aec06600d
Modified Files
--------------
src/backend/regex/regcomp.c | 5 +++-
src/test/regress/expected/regex.out | 49 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/regex.sql | 10 ++++++++
3 files changed, 63 insertions(+), 1 deletion(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression
@ 2019-05-12 22:54 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2019-05-12 22:54 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix misoptimization of "{1,1}" quantifiers in regular expressions.
A bounded quantifier with m = n = 1 might be thought a no-op. But
according to our documentation (which traces back to Henry Spencer's
original man page) it still imposes greediness, or non-greediness in the
case of the non-greedy variant "{1,1}?", on whatever it's attached to.
This turns out not to work though, because parseqatom() optimizes away
the m = n = 1 case without regard for whether it's supposed to change
the greediness of the argument RE.
We can fix this by just not applying the optimization when the greediness
needs to change; the subsequent general cases handle it fine.
The three cases in which we can still apply the optimization are
(a) no quantifier, or quantifier does not impose a preference;
(b) atom has no greediness property, implying it cannot match a
variable amount of text anyway; or
(c) quantifier's greediness is same as atom's.
Note that in most cases where one of these applies, we'd have exited
earlier in the "not a messy case" fast path. I think it's now only
possible to get to the optimization when the atom involves capturing
parentheses or a non-top-level backref.
Back-patch to all supported branches. I'd ordinarily be hesitant to
put a subtle behavioral change into back branches, but in this case
it's very hard to see a reason why somebody would write "{1,1}?" unless
they're trying to get the documented change-of-greediness behavior.
Discussion: https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/940f6479257d5ad297d08d9a205d057b108dca92
Modified Files
--------------
src/backend/regex/regcomp.c | 5 +++-
src/test/regress/expected/regex.out | 49 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/regex.sql | 10 ++++++++
3 files changed, 63 insertions(+), 1 deletion(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression
@ 2019-05-12 22:54 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2019-05-12 22:54 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix misoptimization of "{1,1}" quantifiers in regular expressions.
A bounded quantifier with m = n = 1 might be thought a no-op. But
according to our documentation (which traces back to Henry Spencer's
original man page) it still imposes greediness, or non-greediness in the
case of the non-greedy variant "{1,1}?", on whatever it's attached to.
This turns out not to work though, because parseqatom() optimizes away
the m = n = 1 case without regard for whether it's supposed to change
the greediness of the argument RE.
We can fix this by just not applying the optimization when the greediness
needs to change; the subsequent general cases handle it fine.
The three cases in which we can still apply the optimization are
(a) no quantifier, or quantifier does not impose a preference;
(b) atom has no greediness property, implying it cannot match a
variable amount of text anyway; or
(c) quantifier's greediness is same as atom's.
Note that in most cases where one of these applies, we'd have exited
earlier in the "not a messy case" fast path. I think it's now only
possible to get to the optimization when the atom involves capturing
parentheses or a non-top-level backref.
Back-patch to all supported branches. I'd ordinarily be hesitant to
put a subtle behavioral change into back branches, but in this case
it's very hard to see a reason why somebody would write "{1,1}?" unless
they're trying to get the documented change-of-greediness behavior.
Discussion: https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net
Branch
------
REL9_6_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/2a3dbc151b712a18ef02c03c8bb31b6608c7b56d
Modified Files
--------------
src/backend/regex/regcomp.c | 5 +++-
src/test/regress/expected/regex.out | 49 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/regex.sql | 10 ++++++++
3 files changed, 63 insertions(+), 1 deletion(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression
@ 2019-05-12 22:54 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2019-05-12 22:54 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix misoptimization of "{1,1}" quantifiers in regular expressions.
A bounded quantifier with m = n = 1 might be thought a no-op. But
according to our documentation (which traces back to Henry Spencer's
original man page) it still imposes greediness, or non-greediness in the
case of the non-greedy variant "{1,1}?", on whatever it's attached to.
This turns out not to work though, because parseqatom() optimizes away
the m = n = 1 case without regard for whether it's supposed to change
the greediness of the argument RE.
We can fix this by just not applying the optimization when the greediness
needs to change; the subsequent general cases handle it fine.
The three cases in which we can still apply the optimization are
(a) no quantifier, or quantifier does not impose a preference;
(b) atom has no greediness property, implying it cannot match a
variable amount of text anyway; or
(c) quantifier's greediness is same as atom's.
Note that in most cases where one of these applies, we'd have exited
earlier in the "not a messy case" fast path. I think it's now only
possible to get to the optimization when the atom involves capturing
parentheses or a non-top-level backref.
Back-patch to all supported branches. I'd ordinarily be hesitant to
put a subtle behavioral change into back branches, but in this case
it's very hard to see a reason why somebody would write "{1,1}?" unless
they're trying to get the documented change-of-greediness behavior.
Discussion: https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net
Branch
------
REL9_5_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/d6de52636827ab64f537eb78657db125b082bb65
Modified Files
--------------
src/backend/regex/regcomp.c | 5 +++-
src/test/regress/expected/regex.out | 49 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/regex.sql | 10 ++++++++
3 files changed, 63 insertions(+), 1 deletion(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression
@ 2019-05-12 22:54 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2019-05-12 22:54 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix misoptimization of "{1,1}" quantifiers in regular expressions.
A bounded quantifier with m = n = 1 might be thought a no-op. But
according to our documentation (which traces back to Henry Spencer's
original man page) it still imposes greediness, or non-greediness in the
case of the non-greedy variant "{1,1}?", on whatever it's attached to.
This turns out not to work though, because parseqatom() optimizes away
the m = n = 1 case without regard for whether it's supposed to change
the greediness of the argument RE.
We can fix this by just not applying the optimization when the greediness
needs to change; the subsequent general cases handle it fine.
The three cases in which we can still apply the optimization are
(a) no quantifier, or quantifier does not impose a preference;
(b) atom has no greediness property, implying it cannot match a
variable amount of text anyway; or
(c) quantifier's greediness is same as atom's.
Note that in most cases where one of these applies, we'd have exited
earlier in the "not a messy case" fast path. I think it's now only
possible to get to the optimization when the atom involves capturing
parentheses or a non-top-level backref.
Back-patch to all supported branches. I'd ordinarily be hesitant to
put a subtle behavioral change into back branches, but in this case
it's very hard to see a reason why somebody would write "{1,1}?" unless
they're trying to get the documented change-of-greediness behavior.
Discussion: https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net
Branch
------
REL9_4_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/b1ca28e57e1209769341451c07d7331c822f25a7
Modified Files
--------------
src/backend/regex/regcomp.c | 5 +++-
src/test/regress/expected/regex.out | 49 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/regex.sql | 10 ++++++++
3 files changed, 63 insertions(+), 1 deletion(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2019-05-12 22:54 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-05-12 22:54 pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression Tom Lane <tgl@sss.pgh.pa.us>
2019-05-12 22:54 pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression Tom Lane <tgl@sss.pgh.pa.us>
2019-05-12 22:54 pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression Tom Lane <tgl@sss.pgh.pa.us>
2019-05-12 22:54 pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression Tom Lane <tgl@sss.pgh.pa.us>
2019-05-12 22:54 pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression Tom Lane <tgl@sss.pgh.pa.us>
2019-05-12 22:54 pgsql: Fix misoptimization of "{1, 1}" quantifiers in regular expression Tom Lane <tgl@sss.pgh.pa.us>
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