• Tom Lane's avatar
    Fix infinite loop when splitting inner tuples in SPGiST text indexes. · c170655c
    Tom Lane authored
    Previously, the code used a node label of zero both for strings that
    contain no bytes beyond the inner tuple's prefix, and for cases where an
    "allTheSame" inner tuple has to be split to allow a string with a different
    next byte to be inserted into it.  Failing to distinguish these cases meant
    that if a string ending with the current prefix needed to be inserted into
    an allTheSame tuple, we got into an infinite loop, because after splitting
    the tuple we'd descend into the child allTheSame tuple and then find we
    need to split again.
    
    To fix, instead use -1 and -2 as the node labels for these two cases.
    This requires widening the node label type from "char" to int2, but
    fortunately SPGiST stores all pass-by-value node label types in their
    Datum representation, which means that this change is transparently upward
    compatible so far as the on-disk representation goes.  We continue to
    recognize zero as a dummy node label for reading purposes, but will not
    attempt to push new index entries down into such a label, so that the loop
    won't occur even when dealing with an existing index.
    
    Per report from Teodor Sigaev.  Back-patch to 9.2 where the faulty
    code was introduced.
    c170655c
spgtextproc.c 18.1 KB