v14-0003-Reorder-heap_page_prune_and_freeze-parameters.patch
text/x-patch
Filename: v14-0003-Reorder-heap_page_prune_and_freeze-parameters.patch
Type: text/x-patch
Part: 0
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 v14-0003
Subject: Reorder heap_page_prune_and_freeze parameters
| File | + | − |
|---|---|---|
| src/backend/access/heap/pruneheap.c | 20 | 20 |
| src/backend/access/heap/vacuumlazy.c | 4 | 2 |
| src/include/access/heapam.h | 3 | 3 |
From da4f0d141c8fa673a4651c42efd8bc48cd88c485 Mon Sep 17 00:00:00 2001 From: Melanie Plageman <melanieplageman@gmail.com> Date: Mon, 15 Sep 2025 12:06:19 -0400 Subject: [PATCH v14 03/24] Reorder heap_page_prune_and_freeze parameters Move read-only parameters to the beginning of the function, making it more clear which paramters are inputs and which are input/outputs or outputs. Also const-qualify VacuumCutoffs, which is not modified in heap_page_prune_and_freeze(). --- src/backend/access/heap/pruneheap.c | 40 ++++++++++++++-------------- src/backend/access/heap/vacuumlazy.c | 6 +++-- src/include/access/heapam.h | 6 ++--- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index d8ea0c78f77..28bd6a56749 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -43,7 +43,7 @@ typedef struct bool mark_unused_now; /* whether to attempt freezing tuples */ bool freeze; - struct VacuumCutoffs *cutoffs; + const struct VacuumCutoffs *cutoffs; /*------------------------------------------------------- * Fields describing what to do to the page @@ -260,8 +260,8 @@ heap_page_prune_opt(Relation relation, Buffer buffer) * not the relation has indexes, since we cannot safely determine * that during on-access pruning with the current implementation. */ - heap_page_prune_and_freeze(relation, buffer, vistest, 0, - NULL, &presult, PRUNE_ON_ACCESS, &dummy_off_loc, NULL, NULL); + heap_page_prune_and_freeze(relation, buffer, PRUNE_ON_ACCESS, 0, NULL, + vistest, &presult, &dummy_off_loc, NULL, NULL); /* * Report the number of tuples reclaimed to pgstats. This is @@ -303,7 +303,17 @@ heap_page_prune_opt(Relation relation, Buffer buffer) * also need to account for a reduction in the length of the line pointer * array following array truncation by us. * - * If the HEAP_PRUNE_FREEZE option is set, we will also freeze tuples if it's + * reason indicates why the pruning is performed. It is included in the WAL + * record for debugging and analysis purposes, but otherwise has no effect. + * + * options: + * MARK_UNUSED_NOW indicates that dead items can be set LP_UNUSED during + * pruning. + * + * FREEZE indicates that we will also freeze tuples, and will return + * 'all_visible', 'all_frozen' flags to the caller. + * + * If the HEAP_PRUNE_FREEZE option is set, we will freeze tuples if it's * required in order to advance relfrozenxid / relminmxid, or if it's * considered advantageous for overall system performance to do so now. The * 'cutoffs', 'presult', 'new_relfrozen_xid' and 'new_relmin_mxid' arguments @@ -313,29 +323,19 @@ heap_page_prune_opt(Relation relation, Buffer buffer) * HEAP_PRUNE_FREEZE option is not set, because at the moment only callers * that also freeze need that information. * - * vistest is used to distinguish whether tuples are DEAD or RECENTLY_DEAD - * (see heap_prune_satisfies_vacuum). - * - * options: - * MARK_UNUSED_NOW indicates that dead items can be set LP_UNUSED during - * pruning. - * - * FREEZE indicates that we will also freeze tuples, and will return - * 'all_visible', 'all_frozen' flags to the caller. - * * cutoffs contains the freeze cutoffs, established by VACUUM at the beginning * of vacuuming the relation. Required if HEAP_PRUNE_FREEZE option is set. * cutoffs->OldestXmin is also used to determine if dead tuples are * HEAPTUPLE_RECENTLY_DEAD or HEAPTUPLE_DEAD. * + * vistest is used to distinguish whether tuples are DEAD or RECENTLY_DEAD + * (see heap_prune_satisfies_vacuum). + * * presult contains output parameters needed by callers, such as the number of * tuples removed and the offsets of dead items on the page after pruning. * heap_page_prune_and_freeze() is responsible for initializing it. Required * by all callers. * - * reason indicates why the pruning is performed. It is included in the WAL - * record for debugging and analysis purposes, but otherwise has no effect. - * * off_loc is the offset location required by the caller to use in error * callback. * @@ -348,11 +348,11 @@ heap_page_prune_opt(Relation relation, Buffer buffer) */ void heap_page_prune_and_freeze(Relation relation, Buffer buffer, - GlobalVisState *vistest, + PruneReason reason, int options, - struct VacuumCutoffs *cutoffs, + const struct VacuumCutoffs *cutoffs, + GlobalVisState *vistest, PruneFreezeResult *presult, - PruneReason reason, OffsetNumber *off_loc, TransactionId *new_relfrozen_xid, MultiXactId *new_relmin_mxid) diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 981d9380a92..ddc9677694c 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -1974,8 +1974,10 @@ lazy_scan_prune(LVRelState *vacrel, if (vacrel->nindexes == 0) prune_options |= HEAP_PAGE_PRUNE_MARK_UNUSED_NOW; - heap_page_prune_and_freeze(rel, buf, vacrel->vistest, prune_options, - &vacrel->cutoffs, &presult, PRUNE_VACUUM_SCAN, + heap_page_prune_and_freeze(rel, buf, PRUNE_VACUUM_SCAN, prune_options, + &vacrel->cutoffs, + vacrel->vistest, + &presult, &vacrel->offnum, &vacrel->NewRelfrozenXid, &vacrel->NewRelminMxid); diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index a2bd5a897f8..34206a6a7d5 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -374,11 +374,11 @@ extern TransactionId heap_index_delete_tuples(Relation rel, struct GlobalVisState; extern void heap_page_prune_opt(Relation relation, Buffer buffer); extern void heap_page_prune_and_freeze(Relation relation, Buffer buffer, - struct GlobalVisState *vistest, + PruneReason reason, int options, - struct VacuumCutoffs *cutoffs, + const struct VacuumCutoffs *cutoffs, + struct GlobalVisState *vistest, PruneFreezeResult *presult, - PruneReason reason, OffsetNumber *off_loc, TransactionId *new_relfrozen_xid, MultiXactId *new_relmin_mxid); -- 2.43.0