Fix assorted bugs by changing TS_execute's callback API to ternary logic.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 24 Jul 2020 19:26:51 +0000 (15:26 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 24 Jul 2020 19:26:51 +0000 (15:26 -0400)
commit2f2007fbb255be178aca586780967f43885203a7
treef8b550822ccb33b1a63acc292556c7ee2ae90683
parent25244b8972a34b838c4033fe9efc1d31cba9d0e3
Fix assorted bugs by changing TS_execute's callback API to ternary logic.

Text search sometimes failed to find valid matches, for instance
'!crew:A'::tsquery might fail to locate 'crew:1B'::tsvector during
an index search.  The root of the issue is that TS_execute's callback
functions were not changed to use ternary (yes/no/maybe) reporting
when we made the search logic itself do so.  It's somewhat annoying
to break that API, but on the other hand we now see that any code
using plain boolean logic is almost certainly broken since the
addition of phrase search.  There seem to be very few outside callers
of this code anyway, so we'll just break them intentionally to get
them to adapt.

This allows removal of tsginidx.c's private re-implementation of
TS_execute, since that's now entirely duplicative.  It's also no
longer necessary to avoid use of CALC_NOT in tsgistidx.c, since
the underlying callbacks can now do something reasonable.

Back-patch into v13.  We can't change this in stable branches,
but it seems not quite too late to fix it in v13.

Tom Lane and Pavel Borisov

Discussion: https://postgr.es/m/CALT9ZEE-aLotzBg-pOp2GFTesGWVYzXA3=mZKzRDa_OKnLF7Mg@mail.gmail.com
src/backend/tsearch/wparser_def.c
src/backend/utils/adt/tsginidx.c
src/backend/utils/adt/tsgistidx.c
src/backend/utils/adt/tsrank.c
src/backend/utils/adt/tsvector_op.c
src/include/tsearch/ts_utils.h
src/test/regress/expected/tsearch.out
src/test/regress/expected/tstypes.out
src/test/regress/sql/tsearch.sql
src/test/regress/sql/tstypes.sql