diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 09416450af9..7c23eaf9a85 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -434,7 +434,8 @@ static bool lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, static void lazy_scan_prune(LVRelState *vacrel, Buffer buf, BlockNumber blkno, Page page, Buffer vmbuffer, bool all_visible_according_to_vm, - bool *has_lpdead_items, bool *vm_page_frozen); + bool *has_lpdead_items, bool *vm_page_frozen, + int *ndeleted); static bool lazy_scan_noprune(LVRelState *vacrel, Buffer buf, BlockNumber blkno, Page page, bool *has_lpdead_items); @@ -1245,6 +1246,7 @@ lazy_scan_heap(LVRelState *vacrel) Buffer buf; Page page; uint8 blk_info = 0; + int ndeleted = 0; bool has_lpdead_items; void *per_buffer_data = NULL; bool vm_page_frozen = false; @@ -1390,7 +1392,7 @@ lazy_scan_heap(LVRelState *vacrel) lazy_scan_prune(vacrel, buf, blkno, page, vmbuffer, blk_info & VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM, - &has_lpdead_items, &vm_page_frozen); + &has_lpdead_items, &vm_page_frozen, &ndeleted); /* * Count an eagerly scanned page as a failure or a success. @@ -1481,7 +1483,7 @@ lazy_scan_heap(LVRelState *vacrel) * table has indexes. There will only be newly-freed space if we * held the cleanup lock and lazy_scan_prune() was called. */ - if (got_cleanup_lock && vacrel->nindexes == 0 && has_lpdead_items && + if (got_cleanup_lock && vacrel->nindexes == 0 && ndeleted > 0 && blkno - next_fsm_block_to_vacuum >= VACUUM_FSM_EVERY_PAGES) { FreeSpaceMapVacuumRange(vacrel->rel, next_fsm_block_to_vacuum, @@ -1946,6 +1948,8 @@ cmpOffsetNumbers(const void *a, const void *b) * *vm_page_frozen is set to true if the page is newly set all-frozen in the * VM. The caller currently only uses this for determining whether an eagerly * scanned page was successfully set all-frozen. + * + * *ndeleted is the number of tuples deleted from the page during HOT pruning. */ static void lazy_scan_prune(LVRelState *vacrel, @@ -1955,7 +1959,8 @@ lazy_scan_prune(LVRelState *vacrel, Buffer vmbuffer, bool all_visible_according_to_vm, bool *has_lpdead_items, - bool *vm_page_frozen) + bool *vm_page_frozen, + int *ndeleted) { Relation rel = vacrel->rel; PruneFreezeResult presult; @@ -2063,6 +2068,9 @@ lazy_scan_prune(LVRelState *vacrel, Assert(!presult.all_visible || !(*has_lpdead_items)); + /* Remember the number of tuples deleted from the page for the caller */ + *ndeleted = presult.ndeleted; + /* * Handle setting visibility map bit based on information from the VM (as * of last heap_vac_scan_next_block() call), and from all_visible and