postgresql/src/include/access
Melanie Plageman 648a7e28d7 Eliminate use of cached VM value in lazy_scan_prune()
lazy_scan_prune() takes a parameter from lazy_scan_heap() indicating
whether the page was marked all-visible in the VM at the time it was
last checked in find_next_unskippable_block(). This behavior is
historical, dating back to commit 608195a3a3, when we did not pin the
VM page until deciding we must read it. Now that the VM page is already
pinned, there is no meaningful benefit to relying on a cached VM status.

Removing this cached value simplifies the logic in both lazy_scan_heap()
and lazy_scan_prune(). It also clarifies future work that will set the
visibility map on-access: such paths will not have a cached value
available, which would make the logic harder to reason about. And
eliminating it enables us to detect and repair VM corruption on-access.

Along with removing the cached value and unconditionally checking the
visibility status of the heap page, this commit also moves the VM
corruption handling to occur first. This reordering should have no
performance impact, since the checks are inexpensive and performed only
once per page. It does, however, make the control flow easier to
understand. The new restructuring also makes it possible to set the VM
after fixing corruption (if pruning found the page all-visible).

Now that no callers of visibilitymap_set() use its return value, change
its (and visibilitymap_set_vmbits()) return type to void.

Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/5CEAA162-67B1-44DA-B60D-8B65717E8B05%40gmail.com
2026-01-26 17:00:13 -05:00
..
amapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
amvalidate.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
attmap.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
attnum.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
brin.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
brin_internal.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
brin_page.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
brin_pageops.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
brin_revmap.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
brin_tuple.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
brin_xlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
bufmask.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
clog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
cmptype.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
commit_ts.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
detoast.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
genam.h Move instrumentation-related structs to instrument_node.h 2026-01-12 16:59:28 +01:00
generic_xlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
gin.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
gin_private.h Inline ginCompareAttEntries for speed 2026-01-09 20:31:43 +02:00
gin_tuple.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
ginblock.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
ginxlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
gist.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
gist_private.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
gistscan.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
gistxlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
hash.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
hash_xlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
heapam.h heapam: Add batch mode mvcc check and use it in page mode 2026-01-12 13:22:04 -05:00
heapam_xlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
heaptoast.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
hio.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
htup.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
htup_details.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
itup.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
multixact.h Remove some unnecessary code from multixact truncation 2026-01-15 13:34:50 +02:00
multixact_internal.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
nbtree.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
nbtxlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
parallel.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
printsimple.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
printtup.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
relation.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
reloptions.h Make some use of anonymous unions [reloptions] 2026-01-22 17:04:59 +01:00
relscan.h Stop including {brin,gin}_tuple.h in tuplesort.h 2026-01-12 18:09:49 +01:00
rewriteheap.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
rmgr.h Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
rmgrdesc_utils.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
rmgrlist.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
sdir.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
sequence.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
session.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
skey.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
slru.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
spgist.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
spgist_private.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
spgxlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
stratnum.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
subtrans.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
syncscan.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
sysattr.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
table.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tableam.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tidstore.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
timeline.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
toast_compression.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
toast_helper.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
toast_internals.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
transam.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tsmapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tupconvert.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tupdesc.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tupdesc_details.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tupmacs.h Fix accidentally cast away qualifiers 2026-01-26 16:02:31 +01:00
twophase.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
twophase_rmgr.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
valid.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
visibilitymap.h Eliminate use of cached VM value in lazy_scan_prune() 2026-01-26 17:00:13 -05:00
visibilitymapdefs.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xact.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlog.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlog_internal.h Remove some unnecessary code from multixact truncation 2026-01-15 13:34:50 +02:00
xlogarchive.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogbackup.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogdefs.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xloginsert.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogprefetcher.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogreader.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogrecord.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogrecovery.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogstats.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogutils.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xlogwait.h Extend xlogwait infrastructure with write and flush wait types 2026-01-05 19:56:19 +02:00