pgsql: Fix two serious bugs introduced into hash indexes by the 8.4

From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix two serious bugs introduced into hash indexes by the 8.4
Date: 2009-11-01 21:25:25
Message-ID: 20091101212525.42609753FB7@cvs.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Log Message:
-----------
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.

Modified Files:
--------------
pgsql/src/backend/access/hash:
README (r1.8 -> r1.9)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/access/hash/README?r1=1.8&r2=1.9)
hash.c (r1.113 -> r1.114)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/access/hash/hash.c?r1=1.113&r2=1.114)
hashinsert.c (r1.52 -> r1.53)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/access/hash/hashinsert.c?r1=1.52&r2=1.53)
hashovfl.c (r1.66 -> r1.67)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/access/hash/hashovfl.c?r1=1.66&r2=1.67)
hashpage.c (r1.80 -> r1.81)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/access/hash/hashpage.c?r1=1.80&r2=1.81)
pgsql/src/include/access:
hash.h (r1.93 -> r1.94)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/access/hash.h?r1=1.93&r2=1.94)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2009-11-01 21:25:33 pgsql: Fix two serious bugs introduced into hash indexes by the 8.4
Previous Message User Richtej 2009-11-01 15:07:36 pgsphere - pgsphere: + file COPYRIGHT.pg_sphere added