pgsql: Fix infinite loop when splitting inner tuples in SPGiST text ind - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix infinite loop when splitting inner tuples in SPGiST text ind
Date
Msg-id E1Wu6E5-0003IL-6K@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix infinite loop when splitting inner tuples in SPGiST text indexes.

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.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/93328b2dfb9aa08e5f56a049d84df4ad3c9ff225

Modified Files
--------------
src/backend/access/spgist/spgtextproc.c |  146 +++++++++++++++++++------------
1 file changed, 91 insertions(+), 55 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix infinite loop when splitting inner tuples in SPGiST text ind
Next
From: Tom Lane
Date:
Subject: pgsql: Fix infinite loop when splitting inner tuples in SPGiST text ind