diff options
author | Tom Lane | 2008-07-13 20:45:47 +0000 |
---|---|---|
committer | Tom Lane | 2008-07-13 20:45:47 +0000 |
commit | 8ec0437466bc4bcbfd7f211765e4a7587ff3f4d6 (patch) | |
tree | dfed31431c8739b9ef3be070737f621544044b5d | |
parent | 5750ec0ee69f1376016ae822904be450372ac848 (diff) |
Clean up the use of some page-header-access macros: principally, use
SizeOfPageHeaderData instead of sizeof(PageHeaderData) in places where that
makes the code clearer, and avoid casting between Page and PageHeader where
possible. Zdenek Kotala, with some additional cleanup by Heikki Linnakangas.
I did not apply the parts of the proposed patch that would have resulted in
slightly changing the on-disk format of hash indexes; it seems to me that's
not a win as long as there's any chance of having in-place upgrade for 8.4.
-rw-r--r-- | src/backend/access/gist/gistutil.c | 3 | ||||
-rw-r--r-- | src/backend/access/hash/hashutil.c | 3 | ||||
-rw-r--r-- | src/backend/access/heap/heapam.c | 62 | ||||
-rw-r--r-- | src/backend/access/heap/hio.c | 14 | ||||
-rw-r--r-- | src/backend/access/heap/pruneheap.c | 8 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtpage.c | 5 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 12 | ||||
-rw-r--r-- | src/backend/access/transam/xlogutils.c | 2 | ||||
-rw-r--r-- | src/backend/commands/sequence.c | 12 | ||||
-rw-r--r-- | src/backend/commands/trigger.c | 8 | ||||
-rw-r--r-- | src/backend/optimizer/util/plancat.c | 2 | ||||
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 2 | ||||
-rw-r--r-- | src/include/access/hash.h | 8 | ||||
-rw-r--r-- | src/include/access/htup.h | 12 | ||||
-rw-r--r-- | src/include/access/itup.h | 2 | ||||
-rw-r--r-- | src/include/access/nbtree.h | 5 | ||||
-rw-r--r-- | src/include/access/tuptoaster.h | 6 |
17 files changed, 79 insertions, 87 deletions
diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c index f1c5bab3ba..5162a76cf9 100644 --- a/src/backend/access/gist/gistutil.c +++ b/src/backend/access/gist/gistutil.c @@ -591,8 +591,7 @@ gistcheckpage(Relation rel, Buffer buf) /* * Additionally check that the special area looks sane. */ - if (((PageHeader) (page))->pd_special != - (BLCKSZ - MAXALIGN(sizeof(GISTPageOpaqueData)))) + if (PageGetSpecialSize(page) != MAXALIGN(sizeof(GISTPageOpaqueData))) ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), errmsg("index \"%s\" contains corrupted page at block %u", diff --git a/src/backend/access/hash/hashutil.c b/src/backend/access/hash/hashutil.c index 41e2eef85c..6829097afe 100644 --- a/src/backend/access/hash/hashutil.c +++ b/src/backend/access/hash/hashutil.c @@ -164,8 +164,7 @@ _hash_checkpage(Relation rel, Buffer buf, int flags) /* * Additionally check that the special area looks sane. */ - if (((PageHeader) (page))->pd_special != - (BLCKSZ - MAXALIGN(sizeof(HashPageOpaqueData)))) + if (PageGetSpecialSize(page) != MAXALIGN(sizeof(HashPageOpaqueData))) ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), errmsg("index \"%s\" contains corrupted page at block %u", diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 733e73c5d0..8e851b9275 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -1343,7 +1343,7 @@ heap_fetch(Relation relation, ItemPointer tid = &(tuple->t_self); ItemId lp; Buffer buffer; - PageHeader dp; + Page page; OffsetNumber offnum; bool valid; @@ -1356,14 +1356,14 @@ heap_fetch(Relation relation, * Need share lock on buffer to examine tuple commit status. */ LockBuffer(buffer, BUFFER_LOCK_SHARE); - dp = (PageHeader) BufferGetPage(buffer); + page = BufferGetPage(buffer); /* * We'd better check for out-of-range offnum in case of VACUUM since the * TID was obtained. */ offnum = ItemPointerGetOffsetNumber(tid); - if (offnum < FirstOffsetNumber || offnum > PageGetMaxOffsetNumber(dp)) + if (offnum < FirstOffsetNumber || offnum > PageGetMaxOffsetNumber(page)) { LockBuffer(buffer, BUFFER_LOCK_UNLOCK); if (keep_buf) @@ -1380,7 +1380,7 @@ heap_fetch(Relation relation, /* * get the item line pointer corresponding to the requested tid */ - lp = PageGetItemId(dp, offnum); + lp = PageGetItemId(page, offnum); /* * Must check for deleted tuple. @@ -1402,7 +1402,7 @@ heap_fetch(Relation relation, /* * fill in *tuple fields */ - tuple->t_data = (HeapTupleHeader) PageGetItem((Page) dp, lp); + tuple->t_data = (HeapTupleHeader) PageGetItem(page, lp); tuple->t_len = ItemIdGetLength(lp); tuple->t_tableOid = RelationGetRelid(relation); @@ -1627,7 +1627,7 @@ heap_get_latest_tid(Relation relation, for (;;) { Buffer buffer; - PageHeader dp; + Page page; OffsetNumber offnum; ItemId lp; HeapTupleData tp; @@ -1638,7 +1638,7 @@ heap_get_latest_tid(Relation relation, */ buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(&ctid)); LockBuffer(buffer, BUFFER_LOCK_SHARE); - dp = (PageHeader) BufferGetPage(buffer); + page = BufferGetPage(buffer); /* * Check for bogus item number. This is not treated as an error @@ -1646,12 +1646,12 @@ heap_get_latest_tid(Relation relation, * just assume that the prior tid is OK and return it unchanged. */ offnum = ItemPointerGetOffsetNumber(&ctid); - if (offnum < FirstOffsetNumber || offnum > PageGetMaxOffsetNumber(dp)) + if (offnum < FirstOffsetNumber || offnum > PageGetMaxOffsetNumber(page)) { UnlockReleaseBuffer(buffer); break; } - lp = PageGetItemId(dp, offnum); + lp = PageGetItemId(page, offnum); if (!ItemIdIsNormal(lp)) { UnlockReleaseBuffer(buffer); @@ -1660,7 +1660,7 @@ heap_get_latest_tid(Relation relation, /* OK to access the tuple */ tp.t_self = ctid; - tp.t_data = (HeapTupleHeader) PageGetItem(dp, lp); + tp.t_data = (HeapTupleHeader) PageGetItem(page, lp); tp.t_len = ItemIdGetLength(lp); /* @@ -1964,7 +1964,7 @@ heap_delete(Relation relation, ItemPointer tid, TransactionId xid = GetCurrentTransactionId(); ItemId lp; HeapTupleData tp; - PageHeader dp; + Page page; Buffer buffer; bool have_tuple_lock = false; bool iscombo; @@ -1974,11 +1974,11 @@ heap_delete(Relation relation, ItemPointer tid, buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); - dp = (PageHeader) BufferGetPage(buffer); - lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid)); + page = BufferGetPage(buffer); + lp = PageGetItemId(page, ItemPointerGetOffsetNumber(tid)); Assert(ItemIdIsNormal(lp)); - tp.t_data = (HeapTupleHeader) PageGetItem(dp, lp); + tp.t_data = (HeapTupleHeader) PageGetItem(page, lp); tp.t_len = ItemIdGetLength(lp); tp.t_self = *tid; @@ -2112,7 +2112,7 @@ l1: * the subsequent page pruning will be a no-op and the hint will be * cleared. */ - PageSetPrunable(dp, xid); + PageSetPrunable(page, xid); /* store transaction information of xact deleting the tuple */ tp.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED | @@ -2150,8 +2150,8 @@ l1: recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_DELETE, rdata); - PageSetLSN(dp, recptr); - PageSetTLI(dp, ThisTimeLineID); + PageSetLSN(page, recptr); + PageSetTLI(page, ThisTimeLineID); } END_CRIT_SECTION(); @@ -2276,7 +2276,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, ItemId lp; HeapTupleData oldtup; HeapTuple heaptup; - PageHeader dp; + Page page; Buffer buffer, newbuf; bool need_toast, @@ -2306,11 +2306,11 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(otid)); LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); - dp = (PageHeader) BufferGetPage(buffer); - lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(otid)); + page = BufferGetPage(buffer); + lp = PageGetItemId(page, ItemPointerGetOffsetNumber(otid)); Assert(ItemIdIsNormal(lp)); - oldtup.t_data = (HeapTupleHeader) PageGetItem(dp, lp); + oldtup.t_data = (HeapTupleHeader) PageGetItem(page, lp); oldtup.t_len = ItemIdGetLength(lp); oldtup.t_self = *otid; @@ -2491,7 +2491,7 @@ l2: HeapTupleHasExternal(newtup) || newtup->t_len > TOAST_TUPLE_THRESHOLD); - pagefree = PageGetHeapFreeSpace((Page) dp); + pagefree = PageGetHeapFreeSpace(page); newtupsize = MAXALIGN(newtup->t_len); @@ -2557,7 +2557,7 @@ l2: /* Re-acquire the lock on the old tuple's page. */ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); /* Re-check using the up-to-date free space */ - pagefree = PageGetHeapFreeSpace((Page) dp); + pagefree = PageGetHeapFreeSpace(page); if (newtupsize > pagefree) { /* @@ -2603,7 +2603,7 @@ l2: else { /* Set a hint that the old page could use prune/defrag */ - PageSetFull(dp); + PageSetFull(page); } /* NO EREPORT(ERROR) from here till changes are logged */ @@ -2621,7 +2621,7 @@ l2: * not to optimize for aborts. Note that heap_xlog_update must be kept in * sync if this decision changes. */ - PageSetPrunable(dp, xid); + PageSetPrunable(page, xid); if (use_hot_update) { @@ -2946,7 +2946,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer, HTSU_Result result; ItemPointer tid = &(tuple->t_self); ItemId lp; - PageHeader dp; + Page page; TransactionId xid; TransactionId xmax; uint16 old_infomask; @@ -2959,11 +2959,11 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer, *buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); - dp = (PageHeader) BufferGetPage(*buffer); - lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid)); + page = BufferGetPage(*buffer); + lp = PageGetItemId(page, ItemPointerGetOffsetNumber(tid)); Assert(ItemIdIsNormal(lp)); - tuple->t_data = (HeapTupleHeader) PageGetItem((Page) dp, lp); + tuple->t_data = (HeapTupleHeader) PageGetItem(page, lp); tuple->t_len = ItemIdGetLength(lp); tuple->t_tableOid = RelationGetRelid(relation); @@ -3302,8 +3302,8 @@ l3: recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_LOCK, rdata); - PageSetLSN(dp, recptr); - PageSetTLI(dp, ThisTimeLineID); + PageSetLSN(page, recptr); + PageSetTLI(page, ThisTimeLineID); } END_CRIT_SECTION(); diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c index 18103dd1d9..1e6d9ad54c 100644 --- a/src/backend/access/heap/hio.c +++ b/src/backend/access/heap/hio.c @@ -107,7 +107,7 @@ RelationGetBufferForTuple(Relation relation, Size len, Buffer otherBuffer, bool use_fsm) { Buffer buffer = InvalidBuffer; - Page pageHeader; + Page page; Size pageFreeSpace, saveFreeSpace; BlockNumber targetBlock, @@ -218,8 +218,8 @@ RelationGetBufferForTuple(Relation relation, Size len, * Now we can check to see if there's enough free space here. If so, * we're done. */ - pageHeader = (Page) BufferGetPage(buffer); - pageFreeSpace = PageGetHeapFreeSpace(pageHeader); + page = BufferGetPage(buffer); + pageFreeSpace = PageGetHeapFreeSpace(page); if (len + saveFreeSpace <= pageFreeSpace) { /* use this page as future insert target, too */ @@ -303,16 +303,16 @@ RelationGetBufferForTuple(Relation relation, Size len, * is empty (this should never happen, but if it does we don't want to * risk wiping out valid data). */ - pageHeader = (Page) BufferGetPage(buffer); + page = BufferGetPage(buffer); - if (!PageIsNew((PageHeader) pageHeader)) + if (!PageIsNew(page)) elog(ERROR, "page %u of relation \"%s\" should be empty but is not", BufferGetBlockNumber(buffer), RelationGetRelationName(relation)); - PageInit(pageHeader, BufferGetPageSize(buffer), 0); + PageInit(page, BufferGetPageSize(buffer), 0); - if (len > PageGetHeapFreeSpace(pageHeader)) + if (len > PageGetHeapFreeSpace(page)) { /* We should not get here given the test at the top */ elog(PANIC, "tuple is too big: size %lu", (unsigned long) len); diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index 840045e02f..1327477731 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -72,7 +72,7 @@ static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); void heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) { - PageHeader dp = (PageHeader) BufferGetPage(buffer); + Page page = BufferGetPage(buffer); Size minfree; /* @@ -81,7 +81,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) * Forget it if page is not hinted to contain something prunable that's * older than OldestXmin. */ - if (!PageIsPrunable(dp, OldestXmin)) + if (!PageIsPrunable(page, OldestXmin)) return; /* @@ -100,7 +100,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) HEAP_DEFAULT_FILLFACTOR); minfree = Max(minfree, BLCKSZ / 10); - if (PageIsFull(dp) || PageGetHeapFreeSpace((Page) dp) < minfree) + if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree) { /* OK, try to get exclusive buffer lock */ if (!ConditionalLockBufferForCleanup(buffer)) @@ -112,7 +112,7 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) * prune. (We needn't recheck PageIsPrunable, since no one else could * have pruned while we hold pin.) */ - if (PageIsFull(dp) || PageGetHeapFreeSpace((Page) dp) < minfree) + if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree) { /* OK to prune (though not to remove redirects) */ (void) heap_page_prune(relation, buffer, OldestXmin, false, true); diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c index e7ffa5311f..58faac46be 100644 --- a/src/backend/access/nbtree/nbtpage.c +++ b/src/backend/access/nbtree/nbtpage.c @@ -436,8 +436,7 @@ _bt_checkpage(Relation rel, Buffer buf) /* * Additionally check that the special area looks sane. */ - if (((PageHeader) (page))->pd_special != - (BLCKSZ - MAXALIGN(sizeof(BTPageOpaqueData)))) + if (PageGetSpecialSize(page) != MAXALIGN(sizeof(BTPageOpaqueData))) ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), errmsg("index \"%s\" contains corrupted page at block %u", @@ -555,7 +554,7 @@ _bt_getbuf(Relation rel, BlockNumber blkno, int access) /* Initialize the new page before returning it */ page = BufferGetPage(buf); - Assert(PageIsNew((PageHeader) page)); + Assert(PageIsNew(page)); _bt_pageinit(page, BufferGetPageSize(buf)); } diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index c40fb5b4a0..1e0d7c490b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -1017,19 +1017,19 @@ static bool XLogCheckBuffer(XLogRecData *rdata, bool doPageWrites, XLogRecPtr *lsn, BkpBlock *bkpb) { - PageHeader page; + Page page; - page = (PageHeader) BufferGetBlock(rdata->buffer); + page = BufferGetPage(rdata->buffer); /* * XXX We assume page LSN is first data on *every* page that can be passed * to XLogInsert, whether it otherwise has the standard page layout or * not. */ - *lsn = page->pd_lsn; + *lsn = PageGetLSN(page); if (doPageWrites && - XLByteLE(page->pd_lsn, RedoRecPtr)) + XLByteLE(PageGetLSN(page), RedoRecPtr)) { /* * The page needs to be backed up, so set up *bkpb @@ -1040,8 +1040,8 @@ XLogCheckBuffer(XLogRecData *rdata, bool doPageWrites, if (rdata->buffer_std) { /* Assume we can omit data between pd_lower and pd_upper */ - uint16 lower = page->pd_lower; - uint16 upper = page->pd_upper; + uint16 lower = ((PageHeader) page)->pd_lower; + uint16 upper = ((PageHeader) page)->pd_upper; if (lower >= SizeOfPageHeaderData && upper > lower && diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 801323c481..ad9492f76b 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -279,7 +279,7 @@ XLogReadBuffer(RelFileNode rnode, BlockNumber blkno, bool init) /* check that page has been initialized */ Page page = (Page) BufferGetPage(buffer); - if (PageIsNew((PageHeader) page)) + if (PageIsNew(page)) { UnlockReleaseBuffer(buffer); log_invalid_page(rnode, blkno, true); diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 6333fdcdda..19b5351ba9 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -109,7 +109,7 @@ DefineSequence(CreateSeqStmt *seq) Oid seqoid; Relation rel; Buffer buf; - PageHeader page; + Page page; sequence_magic *sm; HeapTuple tuple; TupleDesc tupDesc; @@ -212,9 +212,9 @@ DefineSequence(CreateSeqStmt *seq) buf = ReadBuffer(rel, P_NEW); Assert(BufferGetBlockNumber(buf) == 0); - page = (PageHeader) BufferGetPage(buf); + page = BufferGetPage(buf); - PageInit((Page) page, BufferGetPageSize(buf), sizeof(sequence_magic)); + PageInit(page, BufferGetPageSize(buf), sizeof(sequence_magic)); sm = (sequence_magic *) PageGetSpecialPointer(page); sm->magic = SEQ_MAGIC; @@ -954,7 +954,7 @@ init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel) static Form_pg_sequence read_info(SeqTable elm, Relation rel, Buffer *buf) { - PageHeader page; + Page page; ItemId lp; HeapTupleData tuple; sequence_magic *sm; @@ -963,7 +963,7 @@ read_info(SeqTable elm, Relation rel, Buffer *buf) *buf = ReadBuffer(rel, 0); LockBuffer(*buf, BUFFER_LOCK_EXCLUSIVE); - page = (PageHeader) BufferGetPage(*buf); + page = BufferGetPage(*buf); sm = (sequence_magic *) PageGetSpecialPointer(page); if (sm->magic != SEQ_MAGIC) @@ -972,7 +972,7 @@ read_info(SeqTable elm, Relation rel, Buffer *buf) lp = PageGetItemId(page, FirstOffsetNumber); Assert(ItemIdIsNormal(lp)); - tuple.t_data = (HeapTupleHeader) PageGetItem((Page) page, lp); + tuple.t_data = (HeapTupleHeader) PageGetItem(page, lp); seq = (Form_pg_sequence) GETSTRUCT(&tuple); diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index f72084940f..4470021de2 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -2203,17 +2203,17 @@ ltrmark:; } else { - PageHeader dp; + Page page; ItemId lp; buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); - dp = (PageHeader) BufferGetPage(buffer); - lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid)); + page = BufferGetPage(buffer); + lp = PageGetItemId(page, ItemPointerGetOffsetNumber(tid)); Assert(ItemIdIsNormal(lp)); - tuple.t_data = (HeapTupleHeader) PageGetItem((Page) dp, lp); + tuple.t_data = (HeapTupleHeader) PageGetItem(page, lp); tuple.t_len = ItemIdGetLength(lp); tuple.t_self = *tid; tuple.t_tableOid = RelationGetRelid(relation); diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 1a4f09e372..2ca6b8bef4 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -429,7 +429,7 @@ estimate_rel_size(Relation rel, int32 *attr_widths, tuple_width += sizeof(HeapTupleHeaderData); tuple_width += sizeof(ItemPointerData); /* note: integer division is intentional here */ - density = (BLCKSZ - sizeof(PageHeaderData)) / tuple_width; + density = (BLCKSZ - SizeOfPageHeaderData) / tuple_width; } *tuples = rint(density * (double) curpages); break; diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 9666fc49a1..33719ba40f 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -263,7 +263,7 @@ ReadBuffer_common(SMgrRelation smgr, bool isLocalBuf, BlockNumber blockNum, * always have left a zero-filled buffer, complain if not PageIsNew. */ bufBlock = isLocalBuf ? LocalBufHdrGetBlock(bufHdr) : BufHdrGetBlock(bufHdr); - if (!PageIsNew((PageHeader) bufBlock)) + if (!PageIsNew((Page) bufBlock)) ereport(ERROR, (errmsg("unexpected data beyond EOF in block %u of relation %u/%u/%u", blockNum, smgr->smgr_rnode.spcNode, smgr->smgr_rnode.dbNode, smgr->smgr_rnode.relNode), diff --git a/src/include/access/hash.h b/src/include/access/hash.h index ab0824d909..1e2b9887d8 100644 --- a/src/include/access/hash.h +++ b/src/include/access/hash.h @@ -166,10 +166,10 @@ typedef HashMetaPageData *HashMetaPage; * Maximum size of a hash index item (it's okay to have only one per page) */ #define HashMaxItemSize(page) \ - (PageGetPageSize(page) - \ - sizeof(PageHeaderData) - \ - MAXALIGN(sizeof(HashPageOpaqueData)) - \ - sizeof(ItemIdData)) + MAXALIGN_DOWN(PageGetPageSize(page) - \ + SizeOfPageHeaderData - \ + sizeof(ItemIdData) - \ + MAXALIGN(sizeof(HashPageOpaqueData))) #define HASH_MIN_FILLFACTOR 10 #define HASH_DEFAULT_FILLFACTOR 75 diff --git a/src/include/access/htup.h b/src/include/access/htup.h index f202959ee7..b101daf6b4 100644 --- a/src/include/access/htup.h +++ b/src/include/access/htup.h @@ -362,12 +362,12 @@ do { \ * other stuff that has to be on a disk page. Since heap pages use no * "special space", there's no deduction for that. * - * NOTE: we do not need to count an ItemId for the tuple because - * sizeof(PageHeaderData) includes the first ItemId on the page. But beware - * of assuming that, say, you can fit 2 tuples of size MaxHeapTupleSize/2 - * on the same page. + * NOTE: we allow for the ItemId that must point to the tuple, ensuring that + * an otherwise-empty page can indeed hold a tuple of this size. Because + * ItemIds and tuples have different alignment requirements, don't assume that + * you can, say, fit 2 tuples of size MaxHeapTupleSize/2 on the same page. */ -#define MaxHeapTupleSize (BLCKSZ - MAXALIGN(sizeof(PageHeaderData))) +#define MaxHeapTupleSize (BLCKSZ - MAXALIGN(SizeOfPageHeaderData + sizeof(ItemIdData))) /* * MaxHeapTuplesPerPage is an upper bound on the number of tuples that can @@ -381,7 +381,7 @@ do { \ * require increases in the size of work arrays. */ #define MaxHeapTuplesPerPage \ - ((int) ((BLCKSZ - offsetof(PageHeaderData, pd_linp)) / \ + ((int) ((BLCKSZ - SizeOfPageHeaderData) / \ (MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + sizeof(ItemIdData)))) /* diff --git a/src/include/access/itup.h b/src/include/access/itup.h index 791fa05d77..c62b88271b 100644 --- a/src/include/access/itup.h +++ b/src/include/access/itup.h @@ -134,7 +134,7 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap; * must be maxaligned, and it must have an associated item pointer. */ #define MaxIndexTuplesPerPage \ - ((int) ((BLCKSZ - offsetof(PageHeaderData, pd_linp)) / \ + ((int) ((BLCKSZ - SizeOfPageHeaderData) / \ (MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData)))) diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h index 3eafe6285d..35eaba61d9 100644 --- a/src/include/access/nbtree.h +++ b/src/include/access/nbtree.h @@ -113,13 +113,10 @@ typedef struct BTMetaPageData * * We actually need to be able to fit three items on every page, * so restrict any one item to 1/3 the per-page available space. - * - * Note: sizeof(PageHeaderData) includes the first ItemId, but we have - * to allow for 2 more, as well as the end-of-page special space. */ #define BTMaxItemSize(page) \ MAXALIGN_DOWN((PageGetPageSize(page) - \ - MAXALIGN(sizeof(PageHeaderData) + 2*sizeof(ItemIdData)) - \ + MAXALIGN(SizeOfPageHeaderData + 3*sizeof(ItemIdData)) - \ MAXALIGN(sizeof(BTPageOpaqueData))) / 3) /* diff --git a/src/include/access/tuptoaster.h b/src/include/access/tuptoaster.h index 57e5c3c64d..24e7d709ec 100644 --- a/src/include/access/tuptoaster.h +++ b/src/include/access/tuptoaster.h @@ -46,10 +46,9 @@ */ #define TOAST_TUPLES_PER_PAGE 4 -/* Note: sizeof(PageHeaderData) includes the first ItemId on the page */ #define TOAST_TUPLE_THRESHOLD \ MAXALIGN_DOWN((BLCKSZ - \ - MAXALIGN(sizeof(PageHeaderData) + (TOAST_TUPLES_PER_PAGE-1) * sizeof(ItemIdData))) \ + MAXALIGN(SizeOfPageHeaderData + TOAST_TUPLES_PER_PAGE * sizeof(ItemIdData))) \ / TOAST_TUPLES_PER_PAGE) #define TOAST_TUPLE_TARGET TOAST_TUPLE_THRESHOLD @@ -73,10 +72,9 @@ */ #define EXTERN_TUPLES_PER_PAGE 4 /* tweak only this */ -/* Note: sizeof(PageHeaderData) includes the first ItemId on the page */ #define EXTERN_TUPLE_MAX_SIZE \ MAXALIGN_DOWN((BLCKSZ - \ - MAXALIGN(sizeof(PageHeaderData) + (EXTERN_TUPLES_PER_PAGE-1) * sizeof(ItemIdData))) \ + MAXALIGN(SizeOfPageHeaderData + EXTERN_TUPLES_PER_PAGE * sizeof(ItemIdData))) \ / EXTERN_TUPLES_PER_PAGE) #define TOAST_MAX_CHUNK_SIZE \ |