From 8e36986cde97522d0ac41d66ce00fc9d0e541585 Mon Sep 17 00:00:00 2001 From: David Christensen Date: Tue, 19 Dec 2023 17:32:38 -0500 Subject: [PATCH v2 5/9] Add Calc, Limit and Dynamic forms of all variable constants --- contrib/bloom/bloom.h | 2 +- src/bin/pg_upgrade/file.c | 2 +- src/include/access/htup_details.h | 13 ++++++++++--- src/include/access/itup.h | 8 ++++++-- src/include/access/nbtree.h | 8 +++++--- src/include/storage/fsm_internals.h | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h index 8331b2ab15..5d45cce80d 100644 --- a/contrib/bloom/bloom.h +++ b/contrib/bloom/bloom.h @@ -112,7 +112,7 @@ typedef struct BloomOptions */ typedef BlockNumber FreeBlockNumberArray[ MAXALIGN_DOWN( - PageUsableSpace - MAXALIGN(sizeof(BloomPageOpaqueData)) + PageUsableSpaceMax - MAXALIGN(sizeof(BloomPageOpaqueData)) - MAXALIGN(sizeof(uint16) * 2 + sizeof(uint32) + sizeof(BloomOptions)) ) / sizeof(BlockNumber) ]; diff --git a/src/bin/pg_upgrade/file.c b/src/bin/pg_upgrade/file.c index bf6c8cc5b9..2860666bc5 100644 --- a/src/bin/pg_upgrade/file.c +++ b/src/bin/pg_upgrade/file.c @@ -187,7 +187,7 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile, struct stat statbuf; /* Compute number of old-format bytes per new page */ - rewriteVmBytesPerPage = (PageUsableSpace) / 2; + rewriteVmBytesPerPage = (PageUsableSpaceMax) / 2; if ((src_fd = open(fromfile, O_RDONLY | PG_BINARY, 0)) < 0) pg_fatal("error while copying relation \"%s.%s\": could not open file \"%s\": %s", diff --git a/src/include/access/htup_details.h b/src/include/access/htup_details.h index 0f7a96820c..70eaac32a7 100644 --- a/src/include/access/htup_details.h +++ b/src/include/access/htup_details.h @@ -560,7 +560,10 @@ StaticAssertDecl(MaxOffsetNumber < SpecTokenOffsetNumber, * 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 (PageUsableSpace - MAXALIGN(sizeof(ItemIdData))) +#define CalcMaxHeapTupleSize(usablespace) ((usablespace) - MAXALIGN(sizeof(ItemIdData))) +#define MaxHeapTupleSizeLimit CalcMaxHeapTupleSize(PageUsableSpaceMax) +#define MaxHeapTupleSizeDynamic CalcMaxHeapTupleSize(PageUsableSpace) +#define MaxHeapTupleSize MaxHeapTupleSizeLimit #define MinHeapTupleSize MAXALIGN(SizeofHeapTupleHeader) /* @@ -574,9 +577,13 @@ StaticAssertDecl(MaxOffsetNumber < SpecTokenOffsetNumber, * pointers to this anyway, to avoid excessive line-pointer bloat and not * require increases in the size of work arrays. */ -#define MaxHeapTuplesPerPage \ - ((int) ((PageUsableSpace) / \ + +#define CalcMaxHeapTuplesPerPage(usablespace) \ + ((int) ((usablespace) / \ (MAXALIGN(SizeofHeapTupleHeader) + sizeof(ItemIdData)))) +#define MaxHeapTuplesPerPageLimit (CalcMaxHeapTuplesPerPage(PageUsableSpaceMax)) +#define MaxHeapTuplesPerPageDynamic (CalcMaxHeapTuplesPerPage(PageUsableSpace)) +#define MaxHeapTuplesPerPage MaxHeapTuplesPerPageLimit /* * MaxAttrSize is a somewhat arbitrary upper limit on the declared size of diff --git a/src/include/access/itup.h b/src/include/access/itup.h index 4e248cb2bb..2fa07cbd3c 100644 --- a/src/include/access/itup.h +++ b/src/include/access/itup.h @@ -163,8 +163,12 @@ index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) * estimated here, seemingly allowing one more tuple than estimated here. * But such a page always has at least MAXALIGN special space, so we're safe. */ -#define MaxIndexTuplesPerPage \ - ((int) ((PageUsableSpace) / \ +#define CalcMaxIndexTuplesPerPage(usablespace) \ + ((int) ((usablespace) / \ (MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData)))) +#define MaxIndexTuplesPerPageLimit (CalcMaxIndexTuplesPerPage(BLCKSZ - SizeOfPageHeaderData)) +#define MaxIndexTuplesPerPageDynamic (CalcMaxIndexTuplesPerPage(PageUsableSpace)) +// temporary to compile +#define MaxIndexTuplesPerPage MaxIndexTuplesPerPageLimit #endif /* ITUP_H */ diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h index 38ad0ade74..907535be60 100644 --- a/src/include/access/nbtree.h +++ b/src/include/access/nbtree.h @@ -182,10 +182,12 @@ typedef struct BTMetaPageData * special area). The value is slightly higher (i.e. more conservative) * than necessary as a result, which is considered acceptable. */ -#define MaxTIDsPerBTreePage \ - (int) ((PageUsableSpace - sizeof(BTPageOpaqueData)) / \ +#define CalcMaxTIDsPerBTreePage(usablespace) \ + (int) ((usablespace) - sizeof(BTPageOpaqueData) / \ sizeof(ItemPointerData)) - +#define MaxTIDsPerBTreePageLimit (CalcMaxTIDsPerBTreePage(PageUsableSpaceMax)) +#define MaxTIDsPerBTreePageDynamic (CalcMaxTIDsPerBTreePage(PageUsableSpace)) +#define MaxTIDsPerBTreePage MaxTIDsPerBTreePageLimit /* * The leaf-page fillfactor defaults to 90% but is user-adjustable. * For pages above the leaf level, we use a fixed 70% fillfactor. diff --git a/src/include/storage/fsm_internals.h b/src/include/storage/fsm_internals.h index 2b9138f7a7..373e2ae92f 100644 --- a/src/include/storage/fsm_internals.h +++ b/src/include/storage/fsm_internals.h @@ -48,7 +48,7 @@ typedef FSMPageData *FSMPage; * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page. * These definitions are internal to fsmpage.c. */ -#define NodesPerPage (PageUsableSpace - \ +#define NodesPerPage (PageUsableSpaceMax - \ offsetof(FSMPageData, fp_nodes)) #define NonLeafNodesPerPage (BLCKSZ / 2 - 1) -- 2.40.1