Skip to content

Commit e1477db

Browse files
Clear up issue with FSM and oldest bpto.xact.
On further reflection, code comments added by commit b0229f2 slightly misrepresented how we determine the oldest bpto.xact for the index. btvacuumpage() does not treat the bpto.xact of a page that it put in the FSM as a candidate to be the oldest deleted page (the delete-marked page that has the oldest bpto.xact XID among all pages encountered). The definition of a deleted page for the purposes of the bpto.xact calculation is different from the definition used by the bulk delete statistics. The bulk delete statistics don't distinguish between pages that were deleted by the current VACUUM, pages deleted by a previous VACUUM operation but not yet recyclable/reusable, and pages that are reusable (though reusable pages are counted separately). Backpatch: 11-, just like commit b0229f2.
1 parent 40708ea commit e1477db

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/backend/access/nbtree/nbtree.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -818,12 +818,6 @@ _bt_vacuum_needs_cleanup(IndexVacuumInfo *info)
818818
* If any oldest btpo.xact from a previously deleted page in the index
819819
* is older than RecentGlobalXmin, then at least one deleted page can
820820
* be recycled -- don't skip cleanup.
821-
*
822-
* Note that btvacuumpage currently doesn't make any effort to
823-
* recognize when a recycled page is already in the FSM (i.e. put
824-
* there by a previous VACUUM operation). We have to be conservative
825-
* because the FSM isn't crash safe. Hopefully recycled pages get
826-
* reused before too long.
827821
*/
828822
result = true;
829823
}
@@ -1073,15 +1067,6 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
10731067

10741068
MemoryContextDelete(vstate.pagedelcontext);
10751069

1076-
/*
1077-
* Maintain a count of the oldest btpo.xact and current number of heap
1078-
* tuples in the metapage (for the benefit of _bt_vacuum_needs_cleanup).
1079-
* The oldest page is typically a page deleted by a previous VACUUM
1080-
* operation.
1081-
*/
1082-
_bt_update_meta_cleanup_info(rel, vstate.oldestBtpoXact,
1083-
info->num_heap_tuples);
1084-
10851070
/*
10861071
* If we found any recyclable pages (and recorded them in the FSM), then
10871072
* forcibly update the upper-level FSM pages to ensure that searchers can
@@ -1097,6 +1082,21 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
10971082
if (vstate.totFreePages > 0)
10981083
IndexFreeSpaceMapVacuum(rel);
10991084

1085+
/*
1086+
* Maintain the oldest btpo.xact and a count of the current number of heap
1087+
* tuples in the metapage (for the benefit of _bt_vacuum_needs_cleanup).
1088+
*
1089+
* The page with the oldest btpo.xact is typically a page deleted by this
1090+
* VACUUM operation, since pages deleted by a previous VACUUM operation
1091+
* tend to be placed in the FSM (by the current VACUUM operation) -- such
1092+
* pages are not candidates to be the oldest btpo.xact. (Note that pages
1093+
* placed in the FSM are reported as deleted pages in the bulk delete
1094+
* statistics, despite not counting as deleted pages for the purposes of
1095+
* determining the oldest btpo.xact.)
1096+
*/
1097+
_bt_update_meta_cleanup_info(rel, vstate.oldestBtpoXact,
1098+
info->num_heap_tuples);
1099+
11001100
/* update statistics */
11011101
stats->num_pages = num_pages;
11021102
stats->pages_free = vstate.totFreePages;

0 commit comments

Comments
 (0)