From 4b85156d26b801a28d815073d533f9b54b68cc9e Mon Sep 17 00:00:00 2001 From: David Christensen Date: Tue, 16 Jan 2024 17:58:00 -0500 Subject: [PATCH v3 13/28] chore: Replace TOAST_MAX_CHUNK_SIZE with ClusterToastMaxSize var Mainly mechanical, computed value will be defined in an upcoming commit. --- contrib/amcheck/verify_heapam.c | 8 ++++---- doc/src/sgml/storage.sgml | 2 +- src/backend/access/common/toast_internals.c | 2 +- src/backend/access/heap/heaptoast.c | 16 ++++++++-------- src/backend/access/transam/xlog.c | 6 +++--- src/bin/pg_resetwal/pg_resetwal.c | 2 +- src/include/access/heaptoast.h | 5 ++--- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c index f2526ed63a..49e2e7dd94 100644 --- a/contrib/amcheck/verify_heapam.c +++ b/contrib/amcheck/verify_heapam.c @@ -1460,7 +1460,7 @@ check_toast_tuple(HeapTuple toasttup, HeapCheckContext *ctx, uint32 extsize) { int32 chunk_seq; - int32 last_chunk_seq = (extsize - 1) / TOAST_MAX_CHUNK_SIZE; + int32 last_chunk_seq = (extsize - 1) / ClusterToastMaxChunkSize; Pointer chunk; bool isnull; int32 chunksize; @@ -1530,8 +1530,8 @@ check_toast_tuple(HeapTuple toasttup, HeapCheckContext *ctx, return; } - expected_size = chunk_seq < last_chunk_seq ? TOAST_MAX_CHUNK_SIZE - : extsize - (last_chunk_seq * TOAST_MAX_CHUNK_SIZE); + expected_size = chunk_seq < last_chunk_seq ? ClusterToastMaxChunkSize + : extsize - (last_chunk_seq * ClusterToastMaxChunkSize); if (chunksize != expected_size) report_toast_corruption(ctx, ta, @@ -1773,7 +1773,7 @@ check_toasted_attribute(HeapCheckContext *ctx, ToastedAttribute *ta) int32 last_chunk_seq; extsize = VARATT_EXTERNAL_GET_EXTSIZE(ta->toast_pointer); - last_chunk_seq = (extsize - 1) / TOAST_MAX_CHUNK_SIZE; + last_chunk_seq = (extsize - 1) / ClusterToastMaxChunkSize; /* * Setup a scan key to find chunks in toast table with matching va_valueid diff --git a/doc/src/sgml/storage.sgml b/doc/src/sgml/storage.sgml index 3ea4e5526d..32ea45b089 100644 --- a/doc/src/sgml/storage.sgml +++ b/doc/src/sgml/storage.sgml @@ -415,7 +415,7 @@ described in more detail below. Out-of-line values are divided (after compression if used) into chunks of at -most TOAST_MAX_CHUNK_SIZE bytes (by default this value is chosen +most ClusterToastMaxChunkSize bytes (by default this value is chosen so that four chunk rows will fit on a page, making it about 2000 bytes). Each chunk is stored as a separate row in the TOAST table belonging to the owning table. Every diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c index 9607ca9a32..7cc4e5f092 100644 --- a/src/backend/access/common/toast_internals.c +++ b/src/backend/access/common/toast_internals.c @@ -311,7 +311,7 @@ toast_save_datum(Relation rel, Datum value, /* * Calculate the size of this chunk */ - chunk_size = Min(TOAST_MAX_CHUNK_SIZE, data_todo); + chunk_size = Min(ClusterToastMaxChunkSize, data_todo); /* * Build a tuple and store it diff --git a/src/backend/access/heap/heaptoast.c b/src/backend/access/heap/heaptoast.c index a420e16530..ada369134a 100644 --- a/src/backend/access/heap/heaptoast.c +++ b/src/backend/access/heap/heaptoast.c @@ -634,7 +634,7 @@ heap_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, SysScanDesc toastscan; HeapTuple ttup; int32 expectedchunk; - int32 totalchunks = ((attrsize - 1) / TOAST_MAX_CHUNK_SIZE) + 1; + int32 totalchunks = ((attrsize - 1) / ClusterToastMaxChunkSize) + 1; int startchunk; int endchunk; int num_indexes; @@ -647,8 +647,8 @@ heap_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, &toastidxs, &num_indexes); - startchunk = sliceoffset / TOAST_MAX_CHUNK_SIZE; - endchunk = (sliceoffset + slicelength - 1) / TOAST_MAX_CHUNK_SIZE; + startchunk = sliceoffset / ClusterToastMaxChunkSize; + endchunk = (sliceoffset + slicelength - 1) / ClusterToastMaxChunkSize; Assert(endchunk <= totalchunks); /* Set up a scan key to fetch from the index. */ @@ -749,8 +749,8 @@ heap_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, curchunk, startchunk, endchunk, valueid, RelationGetRelationName(toastrel)))); - expected_size = curchunk < totalchunks - 1 ? TOAST_MAX_CHUNK_SIZE - : attrsize - ((totalchunks - 1) * TOAST_MAX_CHUNK_SIZE); + expected_size = curchunk < totalchunks - 1 ? ClusterToastMaxChunkSize + : attrsize - ((totalchunks - 1) * ClusterToastMaxChunkSize); if (chunksize != expected_size) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -765,12 +765,12 @@ heap_fetch_toast_slice(Relation toastrel, Oid valueid, int32 attrsize, chcpystrt = 0; chcpyend = chunksize - 1; if (curchunk == startchunk) - chcpystrt = sliceoffset % TOAST_MAX_CHUNK_SIZE; + chcpystrt = sliceoffset % ClusterToastMaxChunkSize; if (curchunk == endchunk) - chcpyend = (sliceoffset + slicelength - 1) % TOAST_MAX_CHUNK_SIZE; + chcpyend = (sliceoffset + slicelength - 1) % ClusterToastMaxChunkSize; memcpy(VARDATA(result) + - (curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt, + (curchunk * ClusterToastMaxChunkSize - sliceoffset) + chcpystrt, chunkdata + chcpystrt, (chcpyend - chcpystrt) + 1); diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 478377c4a2..f9defc70f4 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -4276,9 +4276,9 @@ ReadControlFile(void) if (ControlFile->toast_max_chunk_size != TOAST_MAX_CHUNK_SIZE) ereport(FATAL, (errmsg("database files are incompatible with server"), - errdetail("The database cluster was initialized with TOAST_MAX_CHUNK_SIZE %d," - " but the server was compiled with TOAST_MAX_CHUNK_SIZE %d.", - ControlFile->toast_max_chunk_size, (int) TOAST_MAX_CHUNK_SIZE), + errdetail("The database cluster was initialized with ClusterToastMaxChunkSize %d," + " but the server was configured with ClusterToastMaxChunkSize %d.", + ControlFile->toast_max_chunk_size, (int) ClusterToastMaxChunkSize), errhint("It looks like you need to recompile or initdb."))); if (ControlFile->loblksize != LOBLKSIZE) ereport(FATAL, diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index e9dcb5a6d8..9b02a290e7 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 = ClusterToastMaxChunkSize; ControlFile.loblksize = LOBLKSIZE; ControlFile.float8ByVal = FLOAT8PASSBYVAL; diff --git a/src/include/access/heaptoast.h b/src/include/access/heaptoast.h index 67952565ff..3fbb1d764f 100644 --- a/src/include/access/heaptoast.h +++ b/src/include/access/heaptoast.h @@ -70,13 +70,13 @@ /* * When we store an oversize datum externally, we divide it into chunks - * containing at most TOAST_MAX_CHUNK_SIZE data bytes. This number *must* + * containing at most ClusterToastMaxChunkSize data bytes. This number *must* * be small enough that the completed toast-table tuple (including the * ID and sequence fields and all overhead) will fit on a page. * The coding here sets the size on the theory that we want to fit * EXTERN_TUPLES_PER_PAGE tuples of maximum size onto a page. * - * NB: Changing TOAST_MAX_CHUNK_SIZE requires an initdb. + * NB: Changing ClusterToastMaxChunkSize requires an initdb. */ #define EXTERN_TUPLES_PER_PAGE 4 /* tweak only this */ @@ -91,7 +91,6 @@ VARHDRSZ) #define TOAST_MAX_CHUNK_SIZE_LIMIT CalcToastMaxChunkSize(PageUsableSpaceMax) -#define TOAST_MAX_CHUNK_SIZE CalcToastMaxChunkSize(PageUsableSpace) /* ---------- * heap_toast_insert_or_update - -- 2.40.1