• Tom Lane's avatar
    Fix handling of phrase operator removal while removing tsquery stopwords. · 26044384
    Tom Lane authored
    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
    26044384
tsquery_cleanup.c 17.1 KB