From d4b34f60c54904bb3647911dfd9d79d8a4fab430 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 30 Mar 2020 13:51:12 -0700 Subject: [PATCH] Deduplicate PageIsNew() check in lazy_scan_heap(). The recheck isn't needed anymore, as RelationGetBufferForTuple() now extends the relation with RBM_ZERO_AND_LOCK. Previously we needed to handle the fact that relation extension extended the relation and then separately acquired a lock on the page - while expecting that the page is empty. Reported-By: Ranier Vilela Discussion: https://postgr.es/m/CAEudQArA_=J0D5T258xsCY6Xtf6wiH4b=QDPDgVS+WZUN10WDw@mail.gmail.com --- src/backend/access/heap/vacuumlazy.c | 32 ++++++++++------------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 9726f69629..edda82abd0 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -1147,8 +1147,6 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, if (PageIsNew(page)) { - bool still_new; - /* * All-zeroes pages can be left over if either a backend extends * the relation by a single page, but crashes before the newly @@ -1156,36 +1154,28 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, * the relation (which creates a number of empty pages at the tail * end of the relation, but enters them into the FSM). * - * Make sure these pages are in the FSM, to ensure they can be - * reused. Do that by testing if there's any space recorded for - * the page. If not, enter it. - * * Note we do not enter the page into the visibilitymap. That has * the downside that we repeatedly visit this page in subsequent * vacuums, but otherwise we'll never not discover the space on a * promoted standby. The harm of repeated checking ought to * normally not be too bad - the space usually should be used at * some point, otherwise there wouldn't be any regular vacuums. + * + * Make sure these pages are in the FSM, to ensure they can be + * reused. Do that by testing if there's any space recorded for + * the page. If not, enter it. We do so after releasing the lock + * on the heap page, the FSM is approximate, after all. */ - - /* - * Perform checking of FSM after releasing lock, the fsm is - * approximate, after all. - */ - still_new = PageIsNew(page); UnlockReleaseBuffer(buf); - if (still_new) + empty_pages++; + + if (GetRecordedFreeSpace(onerel, blkno) == 0) { - empty_pages++; + Size freespace; - if (GetRecordedFreeSpace(onerel, blkno) == 0) - { - Size freespace; - - freespace = BufferGetPageSize(buf) - SizeOfPageHeaderData; - RecordPageWithFreeSpace(onerel, blkno, freespace); - } + freespace = BufferGetPageSize(buf) - SizeOfPageHeaderData; + RecordPageWithFreeSpace(onerel, blkno, freespace); } continue; }