8000 Fix missing FSM vacuum opportunities on tables without indexes. · postgres/postgres@7c6eded · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c6eded

Browse files
Fix missing FSM vacuum opportunities on tables without indexes.
Commit c120550 optimized the vacuuming of relations without indexes (a.k.a. one-pass strategy) by directly marking dead item IDs as LP_UNUSED. However, the periodic FSM vacuum was still checking if dead item IDs had been marked as LP_DEAD when attempting to vacuum the FSM every VACUUM_FSM_EVERY_PAGES blocks. This condition was never met due to the optimization, resulting in missed FSM vacuum opportunities. This commit modifies the periodic FSM vacuum condition to use the number of tuples deleted during HOT pruning. This count includes items marked as either LP_UNUSED or LP_REDIRECT, both of which are expected to result in new free space to report. Back-patch to v17 where the vacuum optimization for tables with no indexes was introduced. Reviewed-by: Melanie Plageman <melanieplageman@gmail.com> Discussion: https://postgr.es/m/CAD21AoBL8m6B9GSzQfYxVaEgvD7-Kr3AJaS-hJPHC+avm-29zw@mail.gmail.com Backpatch-through: 17
1 parent 3e73d87 commit 7c6eded

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static void find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis);
431431
static bool lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf,
432432
BlockNumber blkno, Page page,
433433
bool sharelock, Buffer vmbuffer);
434-
static void lazy_scan_prune(LVRelState *vacrel, Buffer buf,
434+
static int lazy_scan_prune(LVRelState *vacrel, Buffer buf,
435435
BlockNumber blkno, Page page,
436436
Buffer vmbuffer, bool all_visible_according_to_vm,
437437
bool *has_lpdead_items, bool *vm_page_frozen);
@@ -1245,6 +1245,7 @@ lazy_scan_heap(LVRelState *vacrel)
12451245
Buffer buf;
12461246
Page page;
12471247
uint8 blk_info = 0;
1248+
int ndeleted = 0;
12481249
bool has_lpdead_items;
12491250
void *per_buffer_data = NULL;
12501251
bool vm_page_frozen = false;
@@ -1387,10 +1388,10 @@ lazy_scan_heap(LVRelState *vacrel)
13871388
* line pointers previously marked LP_DEAD.
13881389
*/
13891390
if (got_cleanup_lock)
1390-
lazy_scan_prune(vacrel, buf, blkno, page,
1391-
vmbuffer,
1392-
blk_info & VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM,
1393-
&has_lpdead_items, &vm_page_frozen);
1391+
ndeleted = lazy_scan_prune(vacrel, buf, blkno, page,
1392+
vmbuffer,
1393+
blk_info & VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM,
1394+
&has_lpdead_items, &vm_page_frozen);
13941395

13951396
/*
13961397
* Count an eagerly scanned page as a failure or a success.
@@ -1481,7 +1482,7 @@ lazy_scan_heap(LVRelState *vacrel)
14811482
* table has indexes. There will only be newly-freed space if we
14821483
* held the cleanup lock and lazy_scan_prune() was called.
14831484
*/
1484-
if (got_cleanup_lock && vacrel->nindexes == 0 && has_lpdead_items &&
1485+
if (got_cleanup_lock && vacrel->nindexes == 0 && ndeleted > 0 &&
14851486
blkno - next_fsm_block_to_vacuum >= VACUUM_FSM_EVERY_PAGES)
14861487
{
14871488
FreeSpaceMapVacuumRange(vacrel->rel, next_fsm_block_to_vacuum,
@@ -1936,8 +1937,10 @@ cmpOffsetNumbers(const void *a, const void *b)
19361937
* *vm_page_frozen is set to true if the page is newly set all-frozen in the
19371938
* VM. The caller currently only uses this for determining whether an eagerly
19381939
* scanned page was successfully set all-frozen.
1940+
*
1941+
* Returns the number of tuples deleted from the page during HOT pruning.
19391942
*/
1940-
static void
1943+
static int
19411944
lazy_scan_prune(LVRelState *vacrel,
19421945
Buffer buf,
19431946
BlockNumber blkno,
@@ -2208,6 +2211,8 @@ lazy_scan_prune(LVRelState *vacrel,
22082211
*vm_page_frozen = true;
22092212
}
22102213
}
2214+
2215+
return presult.ndeleted;
22112216
}
22122217

22132218
/*

0 commit comments

Comments
 (0)
0