Minor bug in suffix truncation of non-key attributes from INCLUDE indexes

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Minor bug in suffix truncation of non-key attributes from INCLUDE indexes
Date: 2020-03-29 00:11:55
Message-ID: CAH2-Wz=E8pkV9ivRSFHtv812H5ckf8s1-yhx61_WrJbKccGcrQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

During a stress test of an experimental patch (which implements a new
technique for managing B-Tree index bloat caused by non-HOT updates),
I noticed a minor bug in _bt_truncate(). The issue affects Postgres 12
+ master.

The problem is that INCLUDE indexes don't have their non-key
attributes physically truncated away in a small minority of cases. I
say "physically" because we nevertheless encode the number of
remaining key attributes in the tuple correctly in all cases (we also
correctly encode the presence or absence of the special pivot tuple
heap TID representation in all cases). That is, we don't consistently
avoid non-key attribute space overhead in the new high key, even
though _bt_truncate() is clearly supposed to consistently avoid said
overhead. Even when it must add a heap TID to the high key using the
special pivot representation of heap TID, it shouldn't have to keep
around the non-key attributes.

This only happens when we cannot truncate away any key columns (and
must therefore include a heap TID in the new leaf high key) in an
INCLUDE index. This condition is rare because in general nbtsplitloc.c
goes out of its way to at least avoid having to include a heap TID in
new leaf page high keys. It's also rare because INCLUDE indexes are
generally only used with unique constraints/indexes, which makes it
particularly likely that nbtsplitloc.c will be able to avoid including
a heap TID in the final high key (unique indexes seldom have enough
duplicates to make nbtsplitloc.c ever use its "single value"
strategy).

Attached patch fixes the issue. Barring objections, I'll push this to
v12 + master branches early next week. The bug is low severity, but
then the fix is very low risk.

--
Peter Geoghegan

Attachment Content-Type Size
v1-0001-Consistently-truncate-non-key-suffix-columns.patch application/octet-stream 886 bytes

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2020-03-29 00:49:20 Re: Improving connection scalability: GetSnapshotData()
Previous Message Tom Lane 2020-03-28 23:26:52 Re: fix for BUG #3720: wrong results at using ltree