From 743ad3a5a9c2f4c01a2c1a2e194f01610d608aa3 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Mon, 28 Sep 2026 09:53:34 +0530 Subject: [PATCH v1] Lock child index before checking its partition parent When creating an index on a partitioned table, DefineIndex() may reuse an existing index on a partition. It calls has_superclass() before locking the child index, though has_superclass() requires it. If ALTER INDEX ... ATTACH PARTITION commits while CREATE INDEX waits for the child index lock, the earlier check becomes stale. CREATE INDEX can then try to attach the child index to a different parent and report "bogus pg_inherit row". Lock the child index before calling has_superclass(), so the check sees the attachment after the lock wait. Close the index when it is already attached. Reported-by: Alexander Lakhin Bug: #19723 --- src/backend/commands/indexcmds.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 5a0312fe772..561dd124e2c 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1453,11 +1453,14 @@ DefineIndex(ParseState *pstate, Relation cldidx; IndexInfo *cldIdxInfo; + cldidx = index_open(cldidxid, lockmode); /* this index is already partition of another one */ if (has_superclass(cldidxid)) + { + index_close(cldidx, lockmode); continue; + } - cldidx = index_open(cldidxid, lockmode); cldIdxInfo = BuildIndexInfo(cldidx); if (CompareIndexInfo(cldIdxInfo, indexInfo, cldidx->rd_indcollation, -- 2.34.1