Skip to content

Commit 7bb9721

Browse files
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 e5d8a99, 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.
1 parent effdd3f commit 7bb9721

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/backend/access/nbtree/nbtree.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,10 @@ _bt_vacuum_needs_cleanup(IndexVacuumInfo *info)
825825
* calls. That is, we can end up scanning the entire index without ever
826826
* placing even 1 of the prev_num_delpages pages in the free space map, at
827827
* least in certain narrow cases (see nbtree/README section on recycling
828-
* deleted pages for details). This rarely matters in practice.
828+
* deleted pages for details). This rarely comes up in practice.
829829
*/
830-
if (prev_num_delpages > RelationGetNumberOfBlocks(info->index) / 20)
830+
if (prev_num_delpages > 0 &&
831+
prev_num_delpages > RelationGetNumberOfBlocks(info->index) / 20)
831832
return true;
832833

833834
return false;
@@ -916,17 +917,12 @@ btvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
916917
}
917918

918919
/*
919-
* By here, we know for sure that this VACUUM operation won't be skipping
920-
* its btvacuumscan() call. Maintain num_delpages value in metapage.
921-
* This information will be used by _bt_vacuum_needs_cleanup() during
922-
* future VACUUM operations that don't need to call btbulkdelete().
920+
* Maintain num_delpages value in metapage for _bt_vacuum_needs_cleanup().
923921
*
924922
* num_delpages is the number of deleted pages now in the index that were
925923
* not safe to place in the FSM to be recycled just yet. We expect that
926924
* it will almost certainly be possible to place all of these pages in the
927-
* FSM during the next VACUUM operation. _bt_vacuum_needs_cleanup() will
928-
* force the next VACUUM to consider this before allowing btvacuumscan()
929-
* to be skipped entirely.
925+
* FSM during the next VACUUM operation.
930926
*/
931927
Assert(stats->pages_deleted >= stats->pages_free);
932928
num_delpages = stats->pages_deleted - stats->pages_free;

0 commit comments

Comments
 (0)