Skip to content

Commit 2a67d64

Browse files
committed
Add commentary explaining why MaxIndexTuplesPerPage calculation is safe.
MaxIndexTuplesPerPage ignores the fact that btree indexes sometimes store tuples with no data payload. But it also ignores the possibility of "special space" on index pages, which offsets that, so that the result isn't an underestimate. This all seems worth documenting, though. In passing, remove #define MinIndexTupleSize, which was added by commit 2c03216 but not used in that commit nor later ones. Comment text by me; issue noticed by Peter Geoghegan. Discussion: https://postgr.es/m/CAH2-WzkQmb54Kbx-YHXstRKXcNc+_87jwV3DRb54xcybLR7Oig@mail.gmail.com
1 parent e013288 commit 2a67d64

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/include/access/itup.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,16 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
132132
* bitmap, so we can safely assume it's at least 1 byte bigger than a bare
133133
* IndexTupleData struct. We arrive at the divisor because each tuple
134134
* must be maxaligned, and it must have an associated item pointer.
135+
*
136+
* To be index-type-independent, this does not account for any special space
137+
* on the page, and is thus conservative.
138+
*
139+
* Note: in btree non-leaf pages, the first tuple has no key (it's implicitly
140+
* minus infinity), thus breaking the "at least 1 byte bigger" assumption.
141+
* On such a page, N tuples could take one MAXALIGN quantum less space than
142+
* estimated here, seemingly allowing one more tuple than estimated here.
143+
* But such a page always has at least MAXALIGN special space, so we're safe.
135144
*/
136-
#define MinIndexTupleSize MAXALIGN(sizeof(IndexTupleData) + 1)
137145
#define MaxIndexTuplesPerPage \
138146
((int) ((BLCKSZ - SizeOfPageHeaderData) / \
139147
(MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData))))

0 commit comments

Comments
 (0)