From e3dd1db8931e00d09d1c29d399f56434146beab3 Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Tue, 14 Oct 2025 15:22:35 -0400 Subject: [PATCH v27 10/14] 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. Reviewed-by: Chao Li --- 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 08ffe511d03..3d34532b766 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -1667,8 +1667,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; @@ -1927,8 +1932,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