diff options
author | Peter Geoghegan | 2021-03-11 22:18:23 +0000 |
---|---|---|
committer | Peter Geoghegan | 2021-03-11 22:18:23 +0000 |
commit | 7bb97211a5589265f3f88183ae9353639ab184c6 (patch) | |
tree | 523f5b1f5ef714c38618ec89f5b10735ce9f68ff /src/backend/access/nbtree/nbtree.c | |
parent | effdd3f3b633e88feaa675377075f02ecc99aee4 (diff) |
Save a few cycles during nbtree VACUUM.
Avoid calling RelationGetNumberOfBlocks() unnecessarily in the common
case where there are no deleted but not yet recycled pages to recycle
during a cleanup-only nbtree VACUUM operation.
Follow-up to commit e5d8a999, which (among other things) taught the
"skip full scan" nbtree VACUUM mechanism to only trigger a full index
scan when the absolute number of deleted pages in the index is
considered excessive.
Diffstat (limited to 'src/backend/access/nbtree/nbtree.c')
-rw-r--r-- | src/backend/access/nbtree/nbtree.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index c70647d6f30..2bcc79ac2fa 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -825,9 +825,10 @@ _bt_vacuum_needs_cleanup(IndexVacuumInfo *info) * calls. That is, we can end up scanning the entire index without ever * placing even 1 of the prev_num_delpages pages in the free space map, at * least in certain narrow cases (see nbtree/README section on recycling - * deleted pages for details). This rarely matters in practice. + * deleted pages for details). This rarely comes up in practice. */ - if (prev_num_delpages > RelationGetNumberOfBlocks(info->index) / 20) + if (prev_num_delpages > 0 && + prev_num_delpages > RelationGetNumberOfBlocks(info->index) / 20) return true; return false; @@ -916,17 +917,12 @@ btvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats) } /* - * By here, we know for sure that this VACUUM operation won't be skipping - * its btvacuumscan() call. Maintain num_delpages value in metapage. - * This information will be used by _bt_vacuum_needs_cleanup() during - * future VACUUM operations that don't need to call btbulkdelete(). + * Maintain num_delpages value in metapage for _bt_vacuum_needs_cleanup(). * * num_delpages is the number of deleted pages now in the index that were * not safe to place in the FSM to be recycled just yet. We expect that * it will almost certainly be possible to place all of these pages in the - * FSM during the next VACUUM operation. _bt_vacuum_needs_cleanup() will - * force the next VACUUM to consider this before allowing btvacuumscan() - * to be skipped entirely. + * FSM during the next VACUUM operation. */ Assert(stats->pages_deleted >= stats->pages_free); num_delpages = stats->pages_deleted - stats->pages_free; |