]> granicus.if.org Git - postgresql/commit
Fix two serious bugs introduced into hash indexes by the 8.4 patch that made
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 1 Nov 2009 21:25:25 +0000 (21:25 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 1 Nov 2009 21:25:25 +0000 (21:25 +0000)
commitc4afdca4c26df63e4942ef300e544c7118c6af56
tree6486e103b606483e5f145c9dda4704c67e11e5dd
parentef59fa0453566ba13ca62d91d5c27050390c8dbb
Fix two serious bugs introduced into hash indexes by the 8.4 patch that made
hash indexes keep entries sorted by hash value.  First, the original plans for
concurrency assumed that insertions would happen only at the end of a page,
which is no longer true; this could cause scans to transiently fail to find
index entries in the presence of concurrent insertions.  We can compensate
by teaching scans to re-find their position after re-acquiring read locks.
Second, neither the bucket split nor the bucket compaction logic had been
fixed to preserve hashvalue ordering, so application of either of those
processes could lead to permanent corruption of an index, in the sense
that searches might fail to find entries that are present.

This patch fixes the split and compaction logic to preserve hashvalue
ordering, but it cannot do anything about pre-existing corruption.  We will
need to recommend reindexing all hash indexes in the 8.4.2 release notes.

To buy back the performance loss hereby induced in split and compaction,
fix them to use PageIndexMultiDelete instead of retail PageIndexDelete
operations.  We might later want to do something with qsort'ing the
page contents rather than doing a binary search for each insertion,
but that seemed more invasive than I cared to risk in a back-patch.

Per bug #5157 from Jeff Janes and subsequent investigation.
src/backend/access/hash/README
src/backend/access/hash/hash.c
src/backend/access/hash/hashinsert.c
src/backend/access/hash/hashovfl.c
src/backend/access/hash/hashpage.c
src/include/access/hash.h