Re: Three more loops that let a function drop a not-yet-processed index/partition

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Baji Shaik <baji(dot)pgdev(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Three more loops that let a function drop a not-yet-processed index/partition
Date: 2026-11-24 04:13:36
Message-ID: awUO8Dlh1GGxnzDB@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Nov 21, 2026 at 12:04:23PM +0900, Michael Paquier wrote:
> On Fri, Nov 20, 2026 at 07:00:49PM -0600, Baji Shaik wrote:
>> While looking at d94964f14f39, I noticed a similar issue in a couple of
>> other
>> code paths which fail with "could not open relation with OID ..." or a
>> cache lookup failure. This happens in plain REINDEX TABLE
>
> Yep. I was aware of this one already, just did not get down to look
> at how to fix it in more details. At quick glance, that seems
> sensible. Thanks for the patch.

After an extra lookup, well, I am afraid that your proposed patch is
not a sensible thing to do.

+ /* Keep every index opened until it is processed below */
+ foreach(indexId, indexIds)
+ {
+ Relation indexRelation = try_index_open(lfirst_oid(indexId),
+ AccessShareLock);
+
+ pinnedRels = lappend(pinnedRels, indexRelation);
+ }

I suspect that this is incorrect for four reasons, at least:
1) This represents a new deadlock risk if running in two separate
session the same REINDEX TABLE.
2) try_index_open() may fail to open an index, leaving the same window
opened, no?
3) This code is used by REPACK, CLUSTER and VACUUM FULL, meaning one
extra relation opened for nothing. That seems like a waste for this
kind of protection, still 1) and 2) are worse.
4) Reorder the two CREATE INDEX queries in your test, the output of
the test is now different.

What the patch states is actually incorrect, no? We don't crash in
the case of a dropped index for a non-concurrent REINDEX TABLE; we
only face a relation lookup failure. It's of course still the wrong
thing to do, but you are overstating the consequences here.

There may be a point in doing an extra syscache lookup to check that
an index still exists, but at the end I am questioning if this part is
worth an effort at all compared to points 1) and 2) mentioned above.
Perhaps in terms of stability we could make that a HEAD-only change,
but nobody is going to hit that in practice anyway?

>> CREATE INDEX on
>> a partitioned table, and ALTER TABLE ... ATTACH PARTITION.
>
> I have not looked at these two.

I suspect that 0002 and 0003 also fail under 1) and 2): more deadlocks
and different outcomes dependings on the ordering. 1) is still the
worse consequence among the two.
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Kyotaro Horiguchi 2026-11-24 04:09:57 Re: postgres_fdw: statistics import can silently fall back to sampling across encodings