v3-0002-Minimize-footprint-of-TOAST_MAX_CHUNK_SIZE-in-hea.patch
text/x-diff
Filename: v3-0002-Minimize-footprint-of-TOAST_MAX_CHUNK_SIZE-in-hea.patch
Type: text/x-diff
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v3-0002
Subject: Minimize footprint of TOAST_MAX_CHUNK_SIZE in heap TOAST code
| File | + | − |
|---|---|---|
| src/backend/access/heap/heaptoast.c | 12 | 8 |
From 5e32e1d6d235c4b1a019852c2678e755f55d8dd6 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@paquier.xyz> Date: Thu, 19 Jun 2025 10:03:46 +0900 Subject: [PATCH v3 02/14] Minimize footprint of TOAST_MAX_CHUNK_SIZE in heap TOAST code This eases a follow-up change to support 8-byte TOAST value IDs, as the maximum chunk size allowed for a single chunk of TOASTed data depends on the size of the value ID. --- src/backend/access/heap/heaptoast.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/backend/access/heap/heaptoast.c b/src/backend/access/heap/heaptoast.c index 76936b2f4944..ae8d502ddcd3 100644 --- a/src/backend/access/heap/heaptoast.c +++ b/src/backend/access/heap/heaptoast.c @@ -634,11 +634,12 @@ heap_fetch_toast_slice(Relation toastrel, uint64 valueid, int32 attrsize, SysScanDesc toastscan; HeapTuple ttup; int32 expectedchunk; - int32 totalchunks = ((attrsize - 1) / TOAST_MAX_CHUNK_SIZE) + 1; + int32 totalchunks; int startchunk; int endchunk; int num_indexes; int validIndex; + int32 max_chunk_size; /* Look for the valid index of toast relation */ validIndex = toast_open_indexes(toastrel, @@ -646,8 +647,11 @@ heap_fetch_toast_slice(Relation toastrel, uint64 valueid, int32 attrsize, &toastidxs, &num_indexes); - startchunk = sliceoffset / TOAST_MAX_CHUNK_SIZE; - endchunk = (sliceoffset + slicelength - 1) / TOAST_MAX_CHUNK_SIZE; + max_chunk_size = TOAST_MAX_CHUNK_SIZE; + + totalchunks = ((attrsize - 1) / max_chunk_size) + 1; + startchunk = sliceoffset / max_chunk_size; + endchunk = (sliceoffset + slicelength - 1) / max_chunk_size; Assert(endchunk <= totalchunks); /* Set up a scan key to fetch from the index. */ @@ -747,8 +751,8 @@ heap_fetch_toast_slice(Relation toastrel, uint64 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 ? max_chunk_size + : attrsize - ((totalchunks - 1) * max_chunk_size); if (chunksize != expected_size) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -763,12 +767,12 @@ heap_fetch_toast_slice(Relation toastrel, uint64 valueid, int32 attrsize, chcpystrt = 0; chcpyend = chunksize - 1; if (curchunk == startchunk) - chcpystrt = sliceoffset % TOAST_MAX_CHUNK_SIZE; + chcpystrt = sliceoffset % max_chunk_size; if (curchunk == endchunk) - chcpyend = (sliceoffset + slicelength - 1) % TOAST_MAX_CHUNK_SIZE; + chcpyend = (sliceoffset + slicelength - 1) % max_chunk_size; memcpy(VARDATA(result) + - (curchunk * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt, + (curchunk * max_chunk_size - sliceoffset) + chcpystrt, chunkdata + chcpystrt, (chcpyend - chcpystrt) + 1); -- 2.50.0