From c870673f91caee78dad2ead25d67e0047d766fd1 Mon Sep 17 00:00:00 2001 From: David Christensen Date: Thu, 18 Jan 2024 13:57:12 -0500 Subject: [PATCH v4 06/22] feature: Add Calc options for toast-related pieces Similar to the other Calc, Limit, etc, --- src/backend/access/common/toast_internals.c | 2 +- src/bin/pg_resetwal/pg_resetwal.c | 2 +- src/include/access/heaptoast.h | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c index 90d0654e62..af72ade4ba 100644 --- a/src/backend/access/common/toast_internals.c +++ b/src/backend/access/common/toast_internals.c @@ -132,7 +132,7 @@ toast_save_datum(Relation rel, Datum value, { struct varlena hdr; /* this is to make the union big enough for a chunk: */ - char data[TOAST_MAX_CHUNK_SIZE + VARHDRSZ]; + char data[TOAST_MAX_CHUNK_SIZE_LIMIT + VARHDRSZ]; /* ensure union is aligned well enough: */ int32 align_it; } chunk_data; diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index e9dcb5a6d8..db5fd71ca0 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -695,7 +695,7 @@ GuessControlValues(void) ControlFile.xlog_seg_size = DEFAULT_XLOG_SEG_SIZE; ControlFile.nameDataLen = NAMEDATALEN; ControlFile.indexMaxKeys = INDEX_MAX_KEYS; - ControlFile.toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE; + ControlFile.toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE_LIMIT; ControlFile.loblksize = LOBLKSIZE; ControlFile.float8ByVal = FLOAT8PASSBYVAL; diff --git a/src/include/access/heaptoast.h b/src/include/access/heaptoast.h index 6fe836f7d1..eba4986559 100644 --- a/src/include/access/heaptoast.h +++ b/src/include/access/heaptoast.h @@ -20,11 +20,12 @@ /* * Find the maximum size of a tuple if there are to be N tuples per page. */ -#define MaximumBytesPerTuple(tuplesPerPage) \ - MAXALIGN_DOWN((BLCKSZ - \ - MAXALIGN(SizeOfPageHeaderData + (tuplesPerPage) * sizeof(ItemIdData))) \ +#define CalcMaximumBytesPerTuple(usablespace,tuplesPerPage) \ + MAXALIGN_DOWN(((usablespace) - ((tuplesPerPage) * sizeof(ItemIdData))) \ / (tuplesPerPage)) +#define MaximumBytesPerTuple(tuplesPerPage) CalcMaximumBytesPerTuple(PageUsableSpaceMax,tuplesPerPage) + /* * These symbols control toaster activation. If a tuple is larger than * TOAST_TUPLE_THRESHOLD, we will try to toast it down to no more than @@ -81,13 +82,17 @@ #define EXTERN_TUPLE_MAX_SIZE MaximumBytesPerTuple(EXTERN_TUPLES_PER_PAGE) -#define TOAST_MAX_CHUNK_SIZE \ - (EXTERN_TUPLE_MAX_SIZE - \ + +#define CalcToastMaxChunkSize(usablespace) \ + (CalcMaximumBytesPerTuple(usablespace,EXTERN_TUPLES_PER_PAGE) - \ MAXALIGN(SizeofHeapTupleHeader) - \ sizeof(Oid) - \ sizeof(int32) - \ VARHDRSZ) +#define TOAST_MAX_CHUNK_SIZE_LIMIT CalcToastMaxChunkSize(PageUsableSpaceMax) +#define TOAST_MAX_CHUNK_SIZE CalcToastMaxChunkSize(PageUsableSpace) + /* ---------- * heap_toast_insert_or_update - * -- 2.40.1