Re: amcheck: add index-all-keys-match verification for B-Tree

From: Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com>
To: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Wenbo Lin <linwenbo1994(at)gmail(dot)com>
Subject: Re: amcheck: add index-all-keys-match verification for B-Tree
Date: 2026-11-18 10:14:42
Message-ID: CAKZiRmzz23Sy5_4vHDBDH2Jubn4oNsabATPsB5p3YKYw9GrJSw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 17, 2026 at 1:54 PM Andrey Borodin <x4mmm(at)yandex-team(dot)ru> wrote:
>
> > On 16 Nov 2026, at 16:25, Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com> wrote:
> >
> > @Andrey: if You are happy
>
> 100%
>
> While testing the additions, I found a little improvement for v7 EOF check:
> ItemPointerGetBlockNumber() is called before validating the TID. With
> a zero heap TID offset, even plain bt_index_check() aborts in an
> assertion-enabled build. Without assertions, the same case passes
> silently.
>
> I think we should check ItemPointerIsValid() and report corruption
> before calling the getters.

0008: Thanks, yeah, it shouldn't hurt and why not error on such cases
just in case. There's was *NoCheck() family of calls that was already
there(without asserts), so it goes rather smoothly. I've added it way above
bt_rootdescend checks as it also calls those (so we fix another bug I
hope)

I've also added minimum guard within bt_report_dangling_index_entry()
for FirstOffsetNumber just in case.

After some tests, my only only remaining doubt is still non-heapAMs: whole
tableAM interface does not seem to have infra to extend amcheck functionality,
so tableAM authors who wants some in-depth verification would have to ship
their own functions in their own extension, but I guess that's nothing new
and best we can do now is to just throw the NOTICE to make user aware.
Or maybe make it DEBUG1, dunno, anyway 0009 is just slight enhacement to
previous 0007.

Maybe we don't squash it yet and set $thread to RfC and it's up to them
to make the decision what to keep as indpendent commit / what to squash
/ what to remove?

keep 0001
keep 0002
keep 0003
keep 0004
keep or squash 0005?
squash 0006 into 0002
squash 0007 into 0002
keep 0008
squash 0009 into 0002
?

-J.

Attachment Content-Type Size
v18112026-0004-pg_amcheck-add-indexallkeysmatch-option.patch text/x-patch 7.8 KB
v18112026-0002-amcheck-detect-dangling-B-Tree-references-.patch text/x-patch 17.7 KB
v18112026-0005-amcheck-verify-against-dangling-btree-poin.patch text/x-patch 1.6 KB
v18112026-0001-amcheck-add-indexallkeysmatch-verification.patch text/x-patch 35.0 KB
v18112026-0003-doc-describe-indexallkeysmatch-verificatio.patch text/x-patch 7.6 KB
v18112026-0007-verify_heapam-make-beyond-EOF-TID-check-he.patch text/x-patch 1.6 KB
v18112026-0006-mention-github-action-runners-CI.patch text/x-patch 1.1 KB
v18112026-0009-amcheck-warn-user-that-non-heapAMs-tables-.patch text/x-patch 2.4 KB
v18112026-0008-amcheck-validate-heap-TIDs-before-calling-.patch text/x-patch 2.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-11-18 10:26:37 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Andrei Lepikhov 2026-11-18 10:01:39 Re: Use local buffer for packed numerics