pgsql: Make contrib/btree_gist's GiST penalty function a bit saner.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make contrib/btree_gist's GiST penalty function a bit saner.
Date: 2013-02-08 00:14:55
Message-ID: E1U3bcF-0004Nb-V4@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
REL9_0_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/f504baaf5535fe0b9298f963e6130fd3d8bab642

Modified Files
--------------
contrib/btree_gist/btree_utils_var.c | 24 ++++++++++--------------
1 files changed, 10 insertions(+), 14 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2013-02-08 00:14:56 pgsql: Make contrib/btree_gist's GiST penalty function a bit saner.
Previous Message Tom Lane 2013-02-07 23:23:15 pgsql: Fix erroneous range-union logic for varlena types in contrib/btr