pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
Subject: [PATCH v3 3/3] Verify redirect items are still correct after heap_page_prune().
Date: Mon, 22 Nov 2021 09:52:45 -0800

---
 src/backend/access/heap/pruneheap.c | 39 +++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

inline patch 1: src/backend/access/heap/pruneheap.c (+39/-0 lines) download inline-1.patchdiff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index d304fd3dcdb..b65c87bb5d7 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -76,6 +76,7 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +static void page_verify_redirects(Page page); /* * Optionally prune and repair fragmentation in the specified page. @@ -885,6 +886,40 @@ heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum) } +static void +page_verify_redirects(Page page) +{ +#ifdef USE_ASSERT_CHECKING + OffsetNumber offnum, + maxoff; + + maxoff = PageGetMaxOffsetNumber(page); + for (offnum = FirstOffsetNumber; + offnum <= maxoff; + offnum = OffsetNumberNext(offnum)) + { + ItemId itemid; + OffsetNumber targoff; + ItemId targitem; + HeapTupleHeader htup; + + itemid = PageGetItemId(page, offnum); + if (!ItemIdIsRedirected(itemid)) + continue; + + targoff = ItemIdGetRedirect(itemid); + targitem = PageGetItemId(page, targoff); + + Assert(ItemIdIsUsed(targitem)); + Assert(ItemIdIsNormal(targitem)); + Assert(ItemIdHasStorage(targitem)); + htup = (HeapTupleHeader) PageGetItem(page, targitem); + Assert(HeapTupleHeaderIsHeapOnly(htup)); + } +#endif +} + + /* * Perform the actual page changes needed by heap_page_prune. * It is expected that the caller has a super-exclusive lock on the @@ -1010,11 +1045,15 @@ heap_page_prune_execute(Buffer buffer, ItemIdSetUnused(lp); } + page_verify_redirects(page); + /* * Finally, repair any fragmentation, and update the page's hint bit about * whether it has free pointers. */ PageRepairFragmentation(page); + + page_verify_redirects(page); } -- 2.34.0
--gfxrd4rbvltax4sz--

Message-ID: <no-message-id-31654@localhost>
Permalink:  ../no-message-id-31654@localhost/
Also on:    postgresql.org/message-id/no-message-id-31654@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: [PATCH v3 3/3] Verify redirect items are still correct after heap_page_prune().
  In-Reply-To: <no-message-id-31654@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox