diff options
author | Andres Freund <andres@anarazel.de> | 2020-03-30 13:51:12 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2020-03-30 13:56:40 -0700 |
commit | d4b34f60c54904bb3647911dfd9d79d8a4fab430 (patch) | |
tree | a363186c37a8e7aca3b8d50009c4a651fe008c30 /src | |
parent | 364bdd0b411343747aeca17708ff7817d7fe0b00 (diff) | |
download | postgresql-d4b34f60c54904bb3647911dfd9d79d8a4fab430.tar.gz postgresql-d4b34f60c54904bb3647911dfd9d79d8a4fab430.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/access/heap/vacuumlazy.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 9726f696298..edda82abd01 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++; + empty_pages++; - if (GetRecordedFreeSpace(onerel, blkno) == 0) - { - 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; } |