Skip to content

Commit 97cda93

Browse files
Consistently truncate non-key suffix columns.
INCLUDE indexes failed to have their non-key attributes physically truncated away in certain rare cases. This led to physically larger pivot tuples that contained useless non-key attribute values. The impact on users should be negligible, but this is still clearly a regression (Postgres 11 supports INCLUDE indexes, and yet was not affected). The bug appeared in commit dd299df, which introduced "true" suffix truncation of key attributes. Discussion: https://postgr.es/m/CAH2-Wz=E8pkV9ivRSFHtv812H5ckf8s1-yhx61_WrJbKccGcrQ@mail.gmail.com Backpatch: 12-, where "true" suffix truncation was introduced.
1 parent de5b9db commit 97cda93

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/access/nbtree/nbtutils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,8 @@ _bt_truncate(Relation rel, IndexTuple lastleft, IndexTuple firstright,
21432143
{
21442144
IndexTuple tidpivot;
21452145

2146-
pivot = index_truncate_tuple(itupdesc, firstright, keepnatts);
2146+
pivot = index_truncate_tuple(itupdesc, firstright,
2147+
Min(keepnatts, nkeyatts));
21472148

21482149
/*
21492150
* If there is a distinguishing key attribute within new pivot tuple,
@@ -2173,6 +2174,10 @@ _bt_truncate(Relation rel, IndexTuple lastleft, IndexTuple firstright,
21732174
/*
21742175
* No truncation was possible, since key attributes are all equal.
21752176
* It's necessary to add a heap TID attribute to the new pivot tuple.
2177+
*
2178+
* This path is only taken when rel is not an INCLUDE index. It
2179+
* avoids a second palloc0() by avoiding the index_truncate_tuple()
2180+
* call completely.
21762181
*/
21772182
Assert(natts == nkeyatts);
21782183
newsize = IndexTupleSize(firstright) + MAXALIGN(sizeof(ItemPointerData));

0 commit comments

Comments
 (0)