postgresql/contrib/pg_trgm
Tom Lane 1dffabed49 Further fix pg_trgm's extraction of trigrams from regular expressions.
Commit 9e43e8714 turns out to have been insufficient: not only is it
necessary to track tentative parent links while considering a set of
arc removals, but it's necessary to track tentative flag additions
as well.  This is because we always merge arc target states into
arc source states; therefore, when considering a merge of the final
state with some other, it is the other state that will acquire a new
TSTATE_FIN bit.  If there's another arc for the same color trigram
that would cause merging of that state with the initial state, we
failed to recognize the problem.  The test cases for the prior commit
evidently only exercised situations where a tentative merge with the
initial state occurs before one with the final state.  If it goes the
other way around, we'll happily merge the initial and final states,
either producing a broken final graph that would never match anything,
or triggering the Assert added by the prior commit.

It's tempting to consider switching the merge direction when the merge
involves the final state, but I lack the time to analyze that idea in
detail.  Instead just keep track of the flag changes that would result
from proposed merges, in the same way that the prior commit tracked
proposed parent links.

Along the way, add some more debugging support, because I'm not entirely
confident that this is the last bug here.  And tweak matters so that
the transformed.dot file uses small integers rather than pointer values
to identify states; that makes it more readable if you're just eyeballing
it rather than fooling with Graphviz.  And rename a couple of identically
named struct fields to reduce confusion.

Per report from Corey Csuhta.  Add a test case based on his example.
(Note: this case does not trigger the bug under 9.3, apparently because
its different measurement of costs causes it to stop merging states before
it hits the failure.  I spent some time trying to find a variant that would
fail in 9.3, without success; but I'm sure such cases exist.)

Like the previous patch, back-patch to 9.3 where this code was added.

Report: https://postgr.es/m/E2B01A4B-4530-406B-8D17-2F67CF9A16BA@csuhta.com
2017-04-14 14:52:21 -04:00
..
data Add files forgotten in f576b17cd6 2016-03-16 19:23:41 +03:00
expected Further fix pg_trgm's extraction of trigrams from regular expressions. 2017-04-14 14:52:21 -04:00
sql Further fix pg_trgm's extraction of trigrams from regular expressions. 2017-04-14 14:52:21 -04:00
.gitignore Support "make check" in contrib 2011-04-25 22:27:11 +03:00
Makefile Handle contrib's GIN/GIST support function signature changes honestly. 2016-06-09 16:44:25 -04:00
pg_trgm--1.0--1.1.sql Fix typo in update scripts for some contrib modules. 2013-07-19 04:13:01 +09:00
pg_trgm--1.1--1.2.sql Add word_similarity to pg_trgm contrib module. 2016-03-16 18:59:21 +03:00
pg_trgm--1.2--1.3.sql pg_trgm's set_limit() function is parallel unsafe, not parallel restricted. 2016-06-20 11:29:54 -04:00
pg_trgm--1.3.sql pg_trgm's set_limit() function is parallel unsafe, not parallel restricted. 2016-06-20 11:29:54 -04:00
pg_trgm--unpackaged--1.0.sql Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
pg_trgm.control Handle contrib's GIN/GIST support function signature changes honestly. 2016-06-09 16:44:25 -04:00
trgm.h Add word_similarity to pg_trgm contrib module. 2016-03-16 18:59:21 +03:00
trgm_gin.c Use wrappers of PG_DETOAST_DATUM_PACKED() more. 2017-03-12 19:35:34 -04:00
trgm_gist.c Use wrappers of PG_DETOAST_DATUM_PACKED() more. 2017-03-12 19:35:34 -04:00
trgm_op.c Use wrappers of PG_DETOAST_DATUM_PACKED() more. 2017-03-12 19:35:34 -04:00
trgm_regexp.c Further fix pg_trgm's extraction of trigrams from regular expressions. 2017-04-14 14:52:21 -04:00