Re: Apply worker can pick an invalid index for REPLICA IDENTITY FULL lookups

From: Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>
To: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Cc: Miłosz Bieniek <bieniek(dot)milosz(at)proton(dot)me>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, onderkalaci(at)gmail(dot)com
Subject: Re: Apply worker can pick an invalid index for REPLICA IDENTITY FULL lookups
Date: 2026-08-25 12:51:01
Message-ID: CANhcyEUSF3VoLYSt+bz9LgoOGtdbnhg9-BBT0xK3C8kpp+04hw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 24 Aug 2026 at 21:23, Mihail Nikalayeu
<mihailnikalayeu(at)gmail(dot)com> wrote:
>
> Hello, Miłosz!
>
> > Any thoughts on moving the 'idxRel->rd_index->indisvalid' check into 'IsIndexUsableForReplicaIdentityFull()' itself?
>
> I initially thought about that approach too, but an assertion also
> uses that check.
> This is explained in the commit message:
>
> > Skip invalid indexes, as the planner does. The test belongs here rather
> > than in IsIndexUsableForReplicaIdentityFull(), whose other caller is an
> > assertion that would then trip over an index DROP INDEX CONCURRENTLY has
> > just invalidated but that still finds tuples fine.
>

Hi Mihail,

I am able to reproduce the issue on HEAD and from PG16 to PG19.

I tested the patch on HEAD and it resolves the issue.
I also agree that the function 'FindUsableIndexForReplicaIdentityFull'
is appropriate. I have manually verified that adding the check in
'IsIndexUsableForReplicaIdentityFull' can cause the Assert to trigger,
when DROP INDEX CONCURRENTLY is run concurrently.

The patch along with changes provided by Amit, looks good to me.

Thanks,
Shlok Kyal

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Sagar Shedge 2026-08-25 12:56:59 Re: [PATCH v1] Report specific wait events for libpq cancel requests
Previous Message Nazir Bilal Yavuz 2026-08-25 12:48:15 aio: Async fsyncs for crash recovery and checkpointer