]> granicus.if.org Git - postgresql/commit
Make contrib/btree_gist's GiST penalty function a bit saner.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Feb 2013 00:14:17 +0000 (19:14 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Feb 2013 00:14:17 +0000 (19:14 -0500)
commitf504baaf5535fe0b9298f963e6130fd3d8bab642
tree844b95a44a5ea313b70e08a36aecbb136dc86626
parent45b315efd83553871e8e966c1c03441b5601a306
Make contrib/btree_gist's GiST penalty function a bit saner.

The previous coding supposed that the first differing bytes in two varlena
datums must have the same sign difference as their overall comparison
result.  This is obviously bogus for text strings in non-C locales, and
probably wrong for numeric, and even for bytea I think it was wrong on
machines where char is signed.  When the assumption failed, the function
could deliver a zero or negative penalty in situations where such a result
is quite ridiculous, leading the core GiST code to make very bad page-split
decisions.

To fix, take the absolute values of the byte-level differences.  Also,
switch the code to using unsigned char not just char, so that the behavior
will be consistent whether char is signed or not.

Per investigation of a trouble report from Tomas Vondra.  Back-patch to all
supported branches.
contrib/btree_gist/btree_utils_var.c