]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Turn visibilitymap_clear() Assert back into an error
authorMelanie Plageman <melanieplageman@gmail.com>
Fri, 17 Jul 2026 20:47:33 +0000 (16:47 -0400)
committerMelanie Plageman <melanieplageman@gmail.com>
Fri, 17 Jul 2026 20:49:14 +0000 (16:49 -0400)
Commit ed62d26caca fixed a bug in clearing the visibility map and, while
doing so, made some incidental changes to visibilitymap_clear(). One of
them replaced the error thrown when the wrong buffer is passed to
visibilitymap_clear() with an Assert().

While anyone adding a new visibilitymap_clear() caller should be running
assert-enabled builds, visibilitymap_set() still reports the same
wrong-buffer condition with an elog(ERROR), so visibilitymap_clear()
should also do so for consistency. This change was also unrelated to
the bug fix and is better made as a separate commit. Restore the error.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwF_PzOv5y7ucFh7Fqqqa8ar83zYwvWugqarRD6%2B7GCtEQ%40mail.gmail.com
Backpatch-through: 19

src/backend/access/heap/visibilitymap.c

index c382b25e192cae5c38026c32ebb7daf94c8ae2e7..bf016dd4c2e227fa33ea1ab2bce6f0b93c792e8e 100644 (file)
@@ -153,9 +153,7 @@ visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf, uint8 flags
 {
        int                     mapByte = HEAPBLK_TO_MAPBYTE(heapBlk);
        int                     mapOffset = HEAPBLK_TO_OFFSET(heapBlk);
-#ifdef USE_ASSERT_CHECKING
        BlockNumber mapBlock = HEAPBLK_TO_MAPBLOCK(heapBlk);
-#endif
        uint8           mask = flags << mapOffset;
        Page            page;
        char       *map;
@@ -169,7 +167,9 @@ visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf, uint8 flags
        elog(DEBUG1, "vm_clear %s %d", RelationGetRelationName(rel), heapBlk);
 #endif
 
-       Assert(BufferIsValid(vmbuf) && BufferGetBlockNumber(vmbuf) == mapBlock);
+       if (!BufferIsValid(vmbuf) || BufferGetBlockNumber(vmbuf) != mapBlock)
+               elog(ERROR, "wrong buffer passed to visibilitymap_clear");
+
        Assert(BufferIsLockedByMeInMode(vmbuf, BUFFER_LOCK_EXCLUSIVE));
 
        page = BufferGetPage(vmbuf);