All-visible pages can't contain prunable tuples. We already clear the
prune hint (pd_prune_xid) during pruning of all-visible pages, but we
were not doing so in vacuum phase three, nor initializing it for
all-frozen pages created by COPY FREEZE, and we were not clearing it on
standbys.
Because page hints are not WAL-logged, pages on a standby carry stale
pd_prune_xid values. After promotion, that stale hint triggers
unnecessary on-access pruning.
Fix this by clearing the prune hint everywhere we currently mark a heap
page all-visible. Clearing it when setting PD_ALL_VISIBLE ensures no
extra overhead.
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/flat/CAAKRu_b-BMOyu0X-0jc_8bWNSbQ5K6JTEueayEhcQuw-OkCSKg%40mail.gmail.com
else if (all_frozen_set)
{
PageSetAllVisible(page);
+ PageClearPrunable(page);
visibilitymap_set_vmbits(BufferGetBlockNumber(buffer),
vmbuffer,
VISIBILITYMAP_ALL_VISIBLE |
* modification would fail to clear the visibility map bit.
*/
if (vmflags & VISIBILITYMAP_VALID_BITS)
+ {
PageSetAllVisible(page);
+ PageClearPrunable(page);
+ }
MarkBufferDirty(buffer);
page = BufferGetPage(buffer);
PageSetAllVisible(page);
+ PageClearPrunable(page);
if (XLogHintBitIsNeeded())
PageSetLSN(page, lsn);
/* XLH_INSERT_ALL_FROZEN_SET implies that all tuples are visible */
if (xlrec->flags & XLH_INSERT_ALL_FROZEN_SET)
+ {
PageSetAllVisible(page);
+ PageClearPrunable(page);
+ }
MarkBufferDirty(buffer);
}
log_newpage_buffer(buf, true);
PageSetAllVisible(page);
+ PageClearPrunable(page);
visibilitymap_set(vacrel->rel, blkno, buf,
InvalidXLogRecPtr,
vmbuffer, InvalidTransactionId,
* the VM bits clear, so there is no point in optimizing it.
*/
PageSetAllVisible(page);
+ PageClearPrunable(page);
MarkBufferDirty(buf);
/*
* set PD_ALL_VISIBLE.
*/
PageSetAllVisible(page);
+ PageClearPrunable(page);
visibilitymap_set_vmbits(blkno,
vmbuffer, vmflags,
vacrel->rel->rd_locator);