aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-12-30 14:29:20 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-12-30 14:53:11 +0200
commit930fd68455576dada48521a6cef642caddea3c63 (patch)
tree431ffa4e45ee378f0c4ffe0b37c0c72cd17c8241
parent3b5a89c4820fb11c337838c1ad71e8e93f2937d1 (diff)
downloadpostgresql-930fd68455576dada48521a6cef642caddea3c63.tar.gz
postgresql-930fd68455576dada48521a6cef642caddea3c63.zip
Revert the GinMaxItemSize calculation so that we fit 3 tuples per page.
Commit 36a35c55 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.
-rw-r--r--src/include/access/gin_private.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index 77f5ffd4bf0..93743df6b8e 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -226,10 +226,18 @@ typedef signed char GinNullCategory;
#define GinGetPosting(itup) ((Pointer) ((char*)(itup) + GinGetPostingOffset(itup)))
#define GinItupIsCompressed(itup) (GinItemPointerGetBlockNumber(&(itup)->t_tid) & GIN_ITUP_COMPRESSED)
+/*
+ * Maximum size of an item on entry tree page. Make sure that we fit at least
+ * three items on each page. (On regular B-tree indexes, we must fit at least
+ * three items: two data items and the "high key". In GIN entry tree, we don't
+ * currently store the high key explicitly, we just use the rightmost item on
+ * the page, so it would actually be enough to fit two items.)
+ */
#define GinMaxItemSize \
Min(INDEX_SIZE_MASK, \
- MAXALIGN_DOWN(((BLCKSZ - SizeOfPageHeaderData - \
- MAXALIGN(sizeof(GinPageOpaqueData))) / 6 - sizeof(ItemIdData))))
+ MAXALIGN_DOWN(((BLCKSZ - \
+ MAXALIGN(SizeOfPageHeaderData + 3 * sizeof(ItemIdData)) - \
+ MAXALIGN(sizeof(GinPageOpaqueData))) / 3)))
/*
* Access macros for non-leaf entry tuples