itup.h says of MinIndexTupleSize/MaxIndexTuplesPerPage:

 * MaxIndexTuplesPerPage is an upper bound on the number of tuples that can
 * fit on one index page.  An index tuple must have either data or a null
 * bitmap, so we can safely assume it's at least 1 byte bigger than a bare
 * IndexTupleData struct.  We arrive at the divisor because each tuple
 * must be maxaligned, and it must have an associated item pointer.
#define MinIndexTupleSize MAXALIGN(sizeof(IndexTupleData) + 1)
#define MaxIndexTuplesPerPage   \
    ((int) ((BLCKSZ - SizeOfPageHeaderData) / \
            (MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData))))

However, that at least seems questionable to me. See _bt_pgaddtup()
for a simple example of this -- "minus infinity" items on internal
pages are sized sizeof(IndexTupleData).

The code still seems fine to me, since that only happens at most once
per page. Is it worth noting the exception?

Peter Geoghegan

Reply via email to