From fc40054e5af31e074a722a4b1836e94d0835a3fe Mon Sep 17 00:00:00 2001 From: David Christensen Date: Thu, 18 Jan 2024 13:57:12 -0500 Subject: [PATCH v3 12/28] feature: Add Calc options for toast-related pieces Similar to the other Calc, Limit, etc, --- src/backend/access/common/toast_internals.c | 2 +- src/include/access/heaptoast.h | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c index a0522fcf5c..9607ca9a32 100644 --- a/src/backend/access/common/toast_internals.c +++ b/src/backend/access/common/toast_internals.c @@ -133,7 +133,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/include/access/heaptoast.h b/src/include/access/heaptoast.h index 7488bd9a53..67952565ff 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(PageUsableSpace,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