Improve handling of dead tuples in hash indexes.
authorRobert Haas <[email protected]>
Tue, 8 Nov 2016 15:47:52 +0000 (10:47 -0500)
committerRobert Haas <[email protected]>
Tue, 8 Nov 2016 15:52:51 +0000 (10:52 -0500)
When squeezing a bucket during vacuum, it's not necessary to retain
any tuples already marked as dead, so ignore them when deciding which
tuples must be moved in order to empty a bucket page.  Similarly, when
splitting a bucket, relocating dead tuples to the new bucket is a
waste of effort; instead, just ignore them.

Amit Kapila, reviewed by me.  Testing help provided by Ashutosh
Sharma.

src/backend/access/hash/hashovfl.c
src/backend/access/hash/hashpage.c

index db3e268a76124ca39020d5b4e3e36ec3e224c333..df7af3ec842399ee0e54f2b20b53710591162b0e 100644 (file)
@@ -656,6 +656,10 @@ _hash_squeezebucket(Relation rel,
            IndexTuple  itup;
            Size        itemsz;
 
+           /* skip dead tuples */
+           if (ItemIdIsDead(PageGetItemId(rpage, roffnum)))
+               continue;
+
            itup = (IndexTuple) PageGetItem(rpage,
                                            PageGetItemId(rpage, roffnum));
            itemsz = IndexTupleDSize(*itup);
index 178463fcb65bbded579271a0c0360d6804833803..a5e9d176a7c0c6d3728996d789cef3ecb3538a2a 100644 (file)
@@ -811,6 +811,10 @@ _hash_splitbucket(Relation rel,
            Size        itemsz;
            Bucket      bucket;
 
+           /* skip dead tuples */
+           if (ItemIdIsDead(PageGetItemId(opage, ooffnum)))
+               continue;
+
            /*
             * Fetch the item's hash key (conveniently stored in the item) and
             * determine which bucket it now belongs in.