Deduplicate PageIsNew() check in lazy_scan_heap().
authorAndres Freund <andres@anarazel.de>
Mon, 30 Mar 2020 20:51:12 +0000 (13:51 -0700)
committerAndres Freund <andres@anarazel.de>
Mon, 30 Mar 2020 20:56:40 +0000 (13:56 -0700)
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

index 9726f696298dab7c4d9346fb519fdec1a0262e22..edda82abd0158a9d77731277e2b4d29ea1af2fa0 100644 (file)
@@ -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;
                }