Re: BUG #19930: amcheck might report btree index corruption after recovery of a mid-deletion state

From: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19930: amcheck might report btree index corruption after recovery of a mid-deletion state
Date: 2026-11-22 19:10:50
Message-ID: CAPHduZCQxTEDiD1ap2=X8cAH0Z+Kw_qNtHJt=q654c+LMHuFZA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sun, Nov 22, 2026 at 11:30 PM Alexander Lakhin <exclusion(at)gmail(dot)com>
wrote:
> Please find the demo test attached.

Hi Alexander,

Thanks for the test. It fails on master for me too.

The cause is that _bt_mark_page_halfdead() marks only the leaf half-dead.
In a multi-level deletion, the internal pages from the subtree's top parent
down to the leaf stay live; only the downlink to the top parent is gone. In
your test the leaf is block 2, its high key names block 3 as the top
parent, and block 8's first downlink already points to block 7.
bt_leftmost_ignoring_half_dead() walks left from block 7, reaches block 3,
and since block 3 is not half-dead, reports the error.

The attached patch also accepts such an internal page: following its only
downlink at each level must reach a half-dead leaf whose high key names
that page, or a page above it on the same path, as the top parent. Your
test is added as t/007_pitr_multilevel.pl and passes with the patch, and
all amcheck tests pass.

To check that it doesn't hide real corruption, I took a copy of the cluster
in the interrupted state and changed the top parent in the leaf's high key
from 3 to 18. The patched amcheck reports the same error again for that
copy.

The patch applies to REL_18_STABLE; REL_17_STABLE needs a separate version.
I didn't test a subtree with more than one internal level.

Regards,
Sai Pranav

Attachment Content-Type Size
v1-0001-amcheck-Accept-an-interrupted-multi-level-btree-p.patch application/octet-stream 10.6 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Alexander Lakhin 2026-11-22 18:00:00 Re: BUG #19930: amcheck might report btree index corruption after recovery of a mid-deletion state