Make contrib/btree_gist's GiST penalty function a bit saner.
authorTom Lane <[email protected]>
Fri, 8 Feb 2013 00:13:59 +0000 (19:13 -0500)
committerTom Lane <[email protected]>
Fri, 8 Feb 2013 00:13:59 +0000 (19:13 -0500)
commit9221f9d485b26d8c663fa2c381e6ecf59b6b3488
treefbcbc17081239488a0af6e06758ee388bc893b18
parent94f565dcf1ada1f2a7c6905f205e14060c4ce08b
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