]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Make VM clear take a RelFileLocator and not fake relcache
authorMelanie Plageman <melanieplageman@gmail.com>
Wed, 15 Jul 2026 21:24:49 +0000 (17:24 -0400)
committerMelanie Plageman <melanieplageman@gmail.com>
Wed, 15 Jul 2026 21:24:49 +0000 (17:24 -0400)
This brings it in line with visibilitymap_set(). An upcoming commit will
start reading visibility map buffers with XLogReadBuffer*() functions,
so we no longer require a relation object to pin the visibility map,
allowing us to remove this fake relcache business altogether.

While we're at it, remove a spurious const qualifier from the
RelFileLocator parameter to visibilitymap_set().

Author: Melanie Plageman <melanieplageman@gmail.com>
Discussion: https://postgr.es/m/flat/CAAKRu_bn%2Be7F4yPFBgFbnP%2BsyJRKyNK092bjD2LKvZW7O4Svag%40mail.gmail.com

contrib/pg_surgery/heap_surgery.c
src/backend/access/heap/heapam.c
src/backend/access/heap/heapam_xlog.c
src/backend/access/heap/pruneheap.c
src/backend/access/heap/visibilitymap.c
src/include/access/visibilitymap.h

index b8ce10957827d449f05d4d7520e33d3035ee84d7..5945727c83475039b38d08db0efb19db8654e9ea 100644 (file)
@@ -267,7 +267,7 @@ heap_force_common(FunctionCallInfo fcinfo, HeapTupleForceOption heap_force_opt)
                                if (PageIsAllVisible(page))
                                {
                                        PageClearAllVisible(page);
-                                       visibilitymap_clear(rel, blkno, vmbuf,
+                                       visibilitymap_clear(rel->rd_locator, blkno, vmbuf,
                                                                                VISIBILITYMAP_VALID_BITS);
                                        did_modify_vm = true;
                                }
index 3f01b694b5adf09903a4e641228609ae5ea4236b..e1396ecbea3588c5c23e995c8394349cd615e7c0 100644 (file)
@@ -2063,7 +2063,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
        {
                all_visible_cleared = true;
                PageClearAllVisible(page);
-               visibilitymap_clear(relation,
+               visibilitymap_clear(relation->rd_locator,
                                                        ItemPointerGetBlockNumber(&(heaptup->t_self)),
                                                        vmbuffer, VISIBILITYMAP_VALID_BITS);
        }
@@ -2442,7 +2442,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
                {
                        all_visible_cleared = true;
                        PageClearAllVisible(page);
-                       visibilitymap_clear(relation,
+                       visibilitymap_clear(relation->rd_locator,
                                                                BufferGetBlockNumber(buffer),
                                                                vmbuffer, VISIBILITYMAP_VALID_BITS);
                }
@@ -3002,7 +3002,7 @@ l1:
        {
                all_visible_cleared = true;
                PageClearAllVisible(page);
-               visibilitymap_clear(relation, BufferGetBlockNumber(buffer),
+               visibilitymap_clear(relation->rd_locator, BufferGetBlockNumber(buffer),
                                                        vmbuffer, VISIBILITYMAP_VALID_BITS);
        }
 
@@ -3836,7 +3836,7 @@ l2:
                 * worthwhile.
                 */
                if (PageIsAllVisible(page) &&
-                       visibilitymap_clear(relation, block, vmbuffer,
+                       visibilitymap_clear(relation->rd_locator, block, vmbuffer,
                                                                VISIBILITYMAP_ALL_FROZEN))
                        cleared_all_frozen = true;
 
@@ -4068,14 +4068,14 @@ l2:
        {
                all_visible_cleared = true;
                PageClearAllVisible(page);
-               visibilitymap_clear(relation, BufferGetBlockNumber(buffer),
+               visibilitymap_clear(relation->rd_locator, BufferGetBlockNumber(buffer),
                                                        vmbuffer, VISIBILITYMAP_VALID_BITS);
        }
        if (newbuf != buffer && PageIsAllVisible(newpage))
        {
                all_visible_cleared_new = true;
                PageClearAllVisible(newpage);
-               visibilitymap_clear(relation, BufferGetBlockNumber(newbuf),
+               visibilitymap_clear(relation->rd_locator, BufferGetBlockNumber(newbuf),
                                                        vmbuffer_new, VISIBILITYMAP_VALID_BITS);
        }
 
@@ -5162,7 +5162,7 @@ failed:
 
        /* Clear only the all-frozen bit on visibility map if needed */
        if (PageIsAllVisible(page) &&
-               visibilitymap_clear(relation, block, vmbuffer,
+               visibilitymap_clear(relation->rd_locator, block, vmbuffer,
                                                        VISIBILITYMAP_ALL_FROZEN))
                cleared_all_frozen = true;
 
@@ -5916,7 +5916,7 @@ l4:
                                                                  &new_xmax, &new_infomask, &new_infomask2);
 
                if (PageIsAllVisible(BufferGetPage(buf)) &&
-                       visibilitymap_clear(rel, block, vmbuffer,
+                       visibilitymap_clear(rel->rd_locator, block, vmbuffer,
                                                                VISIBILITYMAP_ALL_FROZEN))
                        cleared_all_frozen = true;
 
index 963a886a1b366dd24d8cda0cb0d5f447a6295246..31ff6aea2822a616befa7f14590e4376c57046f1 100644 (file)
@@ -314,7 +314,7 @@ heap_xlog_delete(XLogReaderState *record)
                Buffer          vmbuffer = InvalidBuffer;
 
                visibilitymap_pin(reln, blkno, &vmbuffer);
-               visibilitymap_clear(reln, blkno, vmbuffer, VISIBILITYMAP_VALID_BITS);
+               visibilitymap_clear(target_locator, blkno, vmbuffer, VISIBILITYMAP_VALID_BITS);
                ReleaseBuffer(vmbuffer);
                FreeFakeRelcacheEntry(reln);
        }
@@ -403,7 +403,7 @@ heap_xlog_insert(XLogReaderState *record)
                Buffer          vmbuffer = InvalidBuffer;
 
                visibilitymap_pin(reln, blkno, &vmbuffer);
-               visibilitymap_clear(reln, blkno, vmbuffer, VISIBILITYMAP_VALID_BITS);
+               visibilitymap_clear(target_locator, blkno, vmbuffer, VISIBILITYMAP_VALID_BITS);
                ReleaseBuffer(vmbuffer);
                FreeFakeRelcacheEntry(reln);
        }
@@ -536,7 +536,7 @@ heap_xlog_multi_insert(XLogReaderState *record)
                Relation        reln = CreateFakeRelcacheEntry(rlocator);
 
                visibilitymap_pin(reln, blkno, &vmbuffer);
-               visibilitymap_clear(reln, blkno, vmbuffer, VISIBILITYMAP_VALID_BITS);
+               visibilitymap_clear(rlocator, blkno, vmbuffer, VISIBILITYMAP_VALID_BITS);
                ReleaseBuffer(vmbuffer);
                vmbuffer = InvalidBuffer;
                FreeFakeRelcacheEntry(reln);
@@ -758,7 +758,7 @@ heap_xlog_update(XLogReaderState *record, bool hot_update)
                Buffer          vmbuffer = InvalidBuffer;
 
                visibilitymap_pin(reln, oldblk, &vmbuffer);
-               visibilitymap_clear(reln, oldblk, vmbuffer, VISIBILITYMAP_VALID_BITS);
+               visibilitymap_clear(rlocator, oldblk, vmbuffer, VISIBILITYMAP_VALID_BITS);
                ReleaseBuffer(vmbuffer);
                FreeFakeRelcacheEntry(reln);
        }
@@ -844,7 +844,7 @@ heap_xlog_update(XLogReaderState *record, bool hot_update)
                Buffer          vmbuffer = InvalidBuffer;
 
                visibilitymap_pin(reln, newblk, &vmbuffer);
-               visibilitymap_clear(reln, newblk, vmbuffer, VISIBILITYMAP_VALID_BITS);
+               visibilitymap_clear(rlocator, newblk, vmbuffer, VISIBILITYMAP_VALID_BITS);
                ReleaseBuffer(vmbuffer);
                FreeFakeRelcacheEntry(reln);
        }
@@ -1050,7 +1050,7 @@ heap_xlog_lock(XLogReaderState *record)
                reln = CreateFakeRelcacheEntry(rlocator);
 
                visibilitymap_pin(reln, block, &vmbuffer);
-               visibilitymap_clear(reln, block, vmbuffer, VISIBILITYMAP_ALL_FROZEN);
+               visibilitymap_clear(rlocator, block, vmbuffer, VISIBILITYMAP_ALL_FROZEN);
 
                ReleaseBuffer(vmbuffer);
                FreeFakeRelcacheEntry(reln);
@@ -1128,7 +1128,7 @@ heap_xlog_lock_updated(XLogReaderState *record)
                reln = CreateFakeRelcacheEntry(rlocator);
 
                visibilitymap_pin(reln, block, &vmbuffer);
-               visibilitymap_clear(reln, block, vmbuffer, VISIBILITYMAP_ALL_FROZEN);
+               visibilitymap_clear(rlocator, block, vmbuffer, VISIBILITYMAP_ALL_FROZEN);
 
                ReleaseBuffer(vmbuffer);
                FreeFakeRelcacheEntry(reln);
index 6f3ba9113b5223cdbc345748416e395af37bc794..6cf134dfd274d6c4afe5bc5708007ce6db726a90 100644 (file)
@@ -947,7 +947,7 @@ heap_page_fix_vm_corruption(PruneState *prstate, OffsetNumber offnum,
 
        if (do_clear_vm)
        {
-               visibilitymap_clear(prstate->relation, prstate->block,
+               visibilitymap_clear(prstate->relation->rd_locator, prstate->block,
                                                        prstate->vmbuffer,
                                                        VISIBILITYMAP_VALID_BITS);
                prstate->old_vmbits = 0;
index 4fd470702aae70661474340cdba8f50a7d261d52..3b699291b235e3a391ae1f98aff0bda496017536 100644 (file)
@@ -148,7 +148,8 @@ static Buffer vm_extend(Relation rel, BlockNumber vm_nblocks);
  * any I/O.  Returns true if any bits have been cleared and false otherwise.
  */
 bool
-visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf, uint8 flags)
+visibilitymap_clear(RelFileLocator rlocator,
+                                       BlockNumber heapBlk, Buffer vmbuf, uint8 flags)
 {
        BlockNumber mapBlock = HEAPBLK_TO_MAPBLOCK(heapBlk);
        int                     mapByte = HEAPBLK_TO_MAPBYTE(heapBlk);
@@ -162,7 +163,9 @@ visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf, uint8 flags
        Assert(flags != VISIBILITYMAP_ALL_VISIBLE);
 
 #ifdef TRACE_VISIBILITYMAP
-       elog(DEBUG1, "vm_clear %s %d", RelationGetRelationName(rel), heapBlk);
+       elog(DEBUG1, "vm_clear %s %d",
+                relpathbackend(rlocator, MyProcNumber, MAIN_FORKNUM).str,
+                heapBlk);
 #endif
 
        if (!BufferIsValid(vmbuf) || BufferGetBlockNumber(vmbuf) != mapBlock)
@@ -254,7 +257,7 @@ visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf)
 void
 visibilitymap_set(BlockNumber heapBlk,
                                  Buffer vmBuf, uint8 flags,
-                                 const RelFileLocator rlocator)
+                                 RelFileLocator rlocator)
 {
        BlockNumber mapBlock = HEAPBLK_TO_MAPBLOCK(heapBlk);
        uint32          mapByte = HEAPBLK_TO_MAPBYTE(heapBlk);
index e4e0cfa989e147f384b5772e2d09019c7ffc5f14..b860c4ef3ca031e3e36b5c615de30fe3c329d333 100644 (file)
 #define VM_ALL_FROZEN(r, b, v) \
        ((visibilitymap_get_status((r), (b), (v)) & VISIBILITYMAP_ALL_FROZEN) != 0)
 
-extern bool visibilitymap_clear(Relation rel, BlockNumber heapBlk,
+extern bool visibilitymap_clear(RelFileLocator rlocator, BlockNumber heapBlk,
                                                                Buffer vmbuf, uint8 flags);
 extern void visibilitymap_pin(Relation rel, BlockNumber heapBlk,
                                                          Buffer *vmbuf);
 extern bool visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf);
 extern void visibilitymap_set(BlockNumber heapBlk,
                                                          Buffer vmBuf, uint8 flags,
-                                                         const RelFileLocator rlocator);
+                                                         RelFileLocator rlocator);
 extern uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *vmbuf);
 extern void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen);
 extern BlockNumber visibilitymap_prepare_truncate(Relation rel,