[COMMITTERS] pgsql: Fix handling of phrase operator removal while removing tsquerys - Mailing list pgsql-committers

From Tom Lane
Subject [COMMITTERS] pgsql: Fix handling of phrase operator removal while removing tsquerys
Date
Msg-id E1cJ30a-0001cP-GM@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix handling of phrase operator removal while removing tsquery stopwords.

The distance of a removed phrase operator should propagate up to a
parent phrase operator if there is one, but this only worked correctly
in left-deep trees.  Throwing in a few parentheses confused it completely,
as indeed was illustrated by bizarre results in existing regression test
cases.

To fix, track unaccounted-for distances that should propagate to the left
and to the right of the current node, rather than trying to make it work
with only one returned distance.

Also make some adjustments to behave as well as we can for cases of
intermixed phrase and regular (AND/OR) operators.  I don't think it's
possible to be 100% correct for that without a rethinking of the tsquery
representation; for example, maybe we should just not drop stopword nodes
at all underneath phrase operators.  But this is better than it was,
and changing tsquery representation wouldn't be safely back-patchable.

While at it, I simplified the API of the clean_fakeval_intree function
a bit by getting rid of the "char *result" output parameter; that wasn't
doing anything that wasn't redundant with whether the result node is
NULL or not, and testing for NULL seems a lot clearer/safer.

This is part of a larger project to fix various infelicities in the
phrase-search implementation, but this part seems comittable on its own.

Back-patch to 9.6 where phrase operators were introduced.

Discussion: https://postgr.es/m/28215.1481999808@sss.pgh.pa.us
Discussion: https://postgr.es/m/26706.1482087250@sss.pgh.pa.us

Branch
------
REL9_6_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/3f07eff104793cfd82bfd3e093991695221abfd8

Modified Files
--------------
src/backend/utils/adt/tsquery_cleanup.c | 183 +++++++++++++++++++-------------
src/test/regress/expected/tsearch.out   |  18 ++--
2 files changed, 119 insertions(+), 82 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: [COMMITTERS] pgsql: Fix locking problem in _hash_squeezebucket() /_hash_freeovflpag
Next
From: Robert Haas
Date:
Subject: [COMMITTERS] pgsql: Provide a DSA area for all parallel queries.