postgres.git / summary / log / commit / refs

commit    92f375056c11193c26f1278446e6301f0c18ea22
Author:   Peter Geoghegan <pg@bowt.ie>
Date:     Fri Aug 05 03:55:02 2022 +0000
First released in: 16.0

    Fix nbtree maximum item size macro.
    
    Commit dd299df8189, which made heap TID a tiebreaker nbtree index
    column, introduced new rules on page space management to make suffix
    truncation safe for v4+ indexes.  New pivot tuples (generated by suffix
    truncation during leaf page splits) sometimes require dedicated extra
    space at the end of a new leaf page high key/pivot to store a heap TID
    using a special representation (a representation only used in pivot
    tuples).
    
    The definition of "1/3 of a page" was reduced by a single MAXALIGN()
    quantum for v4 indexes to make sure that the final enlarged pivot tuple
    always fit, even with a split point whose firstright tuple happened to
    already be at the "1/3 of a page" limit (limit for non-pivot tuples).
    Internal pages (which only contain pivot tuples) stuck with the original
    "1/3 of a page" definition.  This scheme made it impossible for any page
    split to fail to free enough space for its newitem, which is never okay.
    
    The macro that determines whether non-pivot tuples exceed their "1/3 of
    a leaf page" restriction was structured as if space was needed for all
    three tuples during a leaf page split (the new pivot plus two very large
    adjoining non-pivots that are separated by the split).  This was subtly
    wrong, in that it accidentally relied on implementation details that
    could (at least in theory) change in the future.
    
    To fix, make the macro subtract a single MAXALIGN() quantum, once.  The
    macro evaluates to exactly the same value as before in practice.  But it
    no longer depends on the current layout of nbtree's special area struct.
    
    No backpatch, since this isn't a live bug.
    
    Author: Peter Geoghegan <pg@bowt.ie>
    Reported-By: Robert Haas <robertmhaas@gmail.com>
    Diagnosed-By: Robert Haas <robertmhaas@gmail.com>
    Discussion: https://postgr.es/m/CA+Tgmoa7UBxivM7f6Ocx_qbq4=ky3uXc+WZNOBcVX+kvJvWOEA@mail.gmail.com


src/include/access/nbtree.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h index 93f8267b483..52a422793b0 100644 --- a/src/include/access/nbtree.h +++ b/src/include/access/nbtree.h @@ -163,10 +163,9 @@ typedef struct BTMetaPageData */ #define BTMaxItemSize(page) \ MAXALIGN_DOWN((PageGetPageSize(page) - \ - MAXALIGN(SizeOfPageHeaderData + \ - 3*sizeof(ItemIdData) + \ - 3*sizeof(ItemPointerData)) - \ - MAXALIGN(sizeof(BTPageOpaqueData))) / 3) + MAXALIGN(SizeOfPageHeaderData + 3*sizeof(ItemIdData)) - \ + MAXALIGN(sizeof(BTPageOpaqueData))) / 3) - \ + MAXALIGN(sizeof(ItemPointerData)) #define BTMaxItemSizeNoHeapTid(page) \ MAXALIGN_DOWN((PageGetPageSize(page) - \ MAXALIGN(SizeOfPageHeaderData + 3*sizeof(ItemIdData)) - \ [parent: a0dc82711221]