From 44ba53840d52ca255ddb09acb6fd0cda8559a4db Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Tue, 14 Oct 2025 15:22:35 -0400 Subject: [PATCH v22 7/9] Unset all_visible sooner if not freezing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the prune/freeze path, we currently delay clearing all_visible and all_frozen in the presence of dead items to allow opportunistic freezing. However, if no freezing will be attempted, there’s no need to delay. Clearing the flags earlier avoids extra bookkeeping in heap_prune_record_unchanged_lp_normal(). This currently has no runtime effect because all callers that consider setting the VM also prepare freeze plans, but upcoming changes will allow on-access pruning to set the VM without freezing. The extra bookkeeping was noticeable in a profile of on-access VM setting. --- src/backend/access/heap/pruneheap.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index 040efe80f2e..90270081acd 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -1564,8 +1564,13 @@ heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum, /* * Deliberately delay unsetting all_visible and all_frozen until later * during pruning. Removable dead tuples shouldn't preclude freezing the - * page. + * page. If we won't attempt freezing, just unset all-visible now, though. */ + if (!prstate->attempt_freeze) + { + prstate->all_visible = false; + prstate->all_frozen = false; + } /* Record the dead offset for vacuum */ prstate->deadoffsets[prstate->lpdead_items++] = offnum; @@ -1824,8 +1829,14 @@ heap_prune_record_unchanged_lp_dead(Page page, PruneState *prstate, OffsetNumber * Similarly, don't unset all_visible and all_frozen until later, at the * end of heap_page_prune_and_freeze(). This will allow us to attempt to * freeze the page after pruning. As long as we unset it before updating - * the visibility map, this will be correct. + * the visibility map, this will be correct. If we won't attempt freezing, + * though, just unset all-visible now. */ + if (!prstate->attempt_freeze) + { + prstate->all_visible = false; + prstate->all_frozen = false; + } /* Record the dead offset for vacuum */ prstate->deadoffsets[prstate->lpdead_items++] = offnum; -- 2.43.0