summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2015-10-19 20:54:54 +0000
committerTom Lane2015-10-19 20:54:54 +0000
commit0ce829caf68a95592198d1b45971d11b0f856bb6 (patch)
tree92351b741df87288c3a911846262e2dcf18f9a9c
parenta9bcd8370391a0cdf2aa6af357ba4a735f60390e (diff)
Fix incorrect handling of lookahead constraints in pg_regprefix().
pg_regprefix was doing nothing with lookahead constraints, which would be fine if it were the right kind of nothing, but it isn't: we have to terminate our search for a fixed prefix, not just pretend the LACON arc isn't there. Otherwise, if the current state has both a LACON outarc and a single plain-color outarc, we'd falsely conclude that the color represents an addition to the fixed prefix, and generate an extracted index condition that restricts the indexscan too much. (See added regression test case.) Terminating the search is conservative: we could traverse the LACON arc (thus assuming that the constraint can be satisfied at runtime) and then examine the outarcs of the linked-to state. But that would be a lot more work than it seems worth, because writing a LACON followed by a single plain character is a pretty silly thing to do. This makes a difference only in rather contrived cases, but it's a bug, so back-patch to all supported branches.
-rw-r--r--src/backend/regex/regprefix.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/backend/regex/regprefix.c b/src/backend/regex/regprefix.c
index 6f91288e9df..d0397ed972d 100644
--- a/src/backend/regex/regprefix.c
+++ b/src/backend/regex/regprefix.c
@@ -162,14 +162,12 @@ findprefix(struct cnfa * cnfa,
thiscolor = COLORLESS;
for (ca = cnfa->states[st]; ca->co != COLORLESS; ca++)
{
- /* We ignore lookahead constraints */
- if (ca->co >= cnfa->ncolors)
- continue;
- /* We can also ignore BOS/BOL arcs */
+ /* We can ignore BOS/BOL arcs */
if (ca->co == cnfa->bos[0] || ca->co == cnfa->bos[1])
continue;
- /* ... but EOS/EOL arcs terminate the search */
- if (ca->co == cnfa->eos[0] || ca->co == cnfa->eos[1])
+ /* ... but EOS/EOL arcs terminate the search, as do LACONs */
+ if (ca->co == cnfa->eos[0] || ca->co == cnfa->eos[1] ||
+ ca->co >= cnfa->ncolors)
{
thiscolor = COLORLESS;
break;