Skip to content

Commit 930fd68

Browse files
committed
Revert the GinMaxItemSize calculation so that we fit 3 tuples per page.
Commit 36a35c5 changed the divisor from 3 to 6, for no apparent reason. Reducing GinMaxItemSize like that created a dump/reload hazard: loading a 9.3 database to 9.4 might fail with "index row size XXX exceeds maximum 1352 for index ..." error. Revert the change. While we're at it, make the calculation slightly more accurate. It used to divide the available space on page by three, then subtract sizeof(ItemIdData), and finally round down. That's not totally accurate; the item pointers for the three items are packed tight right after the page header, but there is alignment padding after the item pointers. Change the calculation to reflect that, like BTMaxItemSize does. I tested this with different block sizes on systems with 4- and 8-byte alignment, and the value after the final MAXALIGN_DOWN was the same with both methods on all configurations. So this does not make any difference currently, but let's be tidy. Also add a comment explaining what the macro does. This fixes bug #12292 reported by Robert Thaler. Backpatch to 9.4, where the bug was introduced.
1 parent 3b5a89c commit 930fd68

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/include/access/gin_private.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,18 @@ typedef signed char GinNullCategory;
226226
#define GinGetPosting(itup) ((Pointer) ((char*)(itup) + GinGetPostingOffset(itup)))
227227
#define GinItupIsCompressed(itup) (GinItemPointerGetBlockNumber(&(itup)->t_tid) & GIN_ITUP_COMPRESSED)
228228

229+
/*
230+
* Maximum size of an item on entry tree page. Make sure that we fit at least
231+
* three items on each page. (On regular B-tree indexes, we must fit at least
232+
* three items: two data items and the "high key". In GIN entry tree, we don't
233+
* currently store the high key explicitly, we just use the rightmost item on
234+
* the page, so it would actually be enough to fit two items.)
235+
*/
229236
#define GinMaxItemSize \
230237
Min(INDEX_SIZE_MASK, \
231-
MAXALIGN_DOWN(((BLCKSZ - SizeOfPageHeaderData - \
232-
MAXALIGN(sizeof(GinPageOpaqueData))) / 6 - sizeof(ItemIdData))))
238+
MAXALIGN_DOWN(((BLCKSZ - \
239+
MAXALIGN(SizeOfPageHeaderData + 3 * sizeof(ItemIdData)) - \
240+
MAXALIGN(sizeof(GinPageOpaqueData))) / 3)))
233241

234242
/*
235243
* Access macros for non-leaf entry tuples

0 commit comments

Comments
 (0)