postgresql/src
Tom Lane 166d534fcd Repair bugs in GiST page splitting code for multi-column indexes.
When considering a non-last column in a multi-column GiST index,
gistsplit.c tries to improve on the split chosen by the opclass-specific
pickSplit function by considering penalties for the next column.  However,
there were two bugs in this code: it failed to recompute the union keys for
the leftmost index columns, even though these might well change after
reassigning tuples; and it included the old union keys in the recomputation
for the columns it did recompute, so that those keys couldn't get smaller
even if they should.  The first problem could result in an invalid index
in which searches wouldn't find index entries that are in fact present;
the second would make the index less efficient to search.

Both of these errors were caused by misuse of gistMakeUnionItVec, whose
API was designed in a way that just begged such errors to be made.  There
is no situation in which it's safe or useful to compute the union keys for
a subset of the index columns, and there is no caller that wants any
previous union keys to be included in the computation; so the undocumented
choice to treat the union keys as in/out rather than pure output parameters
is a waste of code as well as being dangerous.

Hence, rather than just making a minimal patch, I've changed the API of
gistMakeUnionItVec to remove the "startkey" parameter (it now always
processes all index columns) and treat the attr/isnull arrays as purely
output parameters.

In passing, also get rid of a couple of unnecessary and dangerous uses
of static variables in gistutil.c.  It's remarkable that the one in
gistMakeUnionKey hasn't given us portability troubles before now, because
in addition to posing a re-entrancy hazard, it was unsafely assuming that
a static char[] array would have at least Datum alignment.

Per investigation of a trouble report from Tomas Vondra.  (There are also
some bugs in contrib/btree_gist to be fixed, but that seems like material
for a separate patch.)  Back-patch to all supported branches.
2013-02-07 17:44:02 -05:00
..
backend Repair bugs in GiST page splitting code for multi-column indexes. 2013-02-07 17:44:02 -05:00
bin Enable building with Microsoft Visual Studio 2012. 2013-02-06 14:52:29 -05:00
include Repair bugs in GiST page splitting code for multi-column indexes. 2013-02-07 17:44:02 -05:00
interfaces Provide database object names as separate fields in error messages. 2013-01-29 17:08:26 -05:00
makefiles Make pgxs build executables with the right suffix. 2013-01-19 14:54:29 -05:00
pl PL/Python: Add result object str handler 2013-02-03 00:31:01 -05:00
port Enable building with Microsoft Visual Studio 2012. 2013-02-06 14:52:29 -05:00
template Remove _FORTIFY_SOURCE 2012-10-10 21:42:38 -04:00
test Perform line wrapping and indenting by default in ruleutils.c. 2013-02-03 15:56:45 -05:00
timezone Add new timezone abbrevation "FET". 2013-01-14 14:45:40 -05:00
tools Enable building with Microsoft Visual Studio 2012. 2013-02-06 14:52:29 -05:00
tutorial Modernize string literal syntax in tutorial example. 2013-01-19 17:20:32 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Fix some oversights in distprep and maintainer-clean targets. 2011-03-10 00:04:05 -05:00
Makefile.global.in PL/Python: Make build on OS X more flexible 2013-01-05 08:56:14 -05:00
Makefile.shlib Remove configure flag --disable-shared, as it is no longer used by any 2012-08-30 16:26:53 -04:00
nls-global.mk NLS: Use msgmerge --previous option 2012-12-13 23:12:12 -05:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00