Re: BUG #19723: CREATE INDEX racing with ALTER INDEX ATTACH PARTITION triggers unexpected internal error

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Rafia Sabih <rafia(dot)pghackers(at)gmail(dot)com>
Cc: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19723: CREATE INDEX racing with ALTER INDEX ATTACH PARTITION triggers unexpected internal error
Date: 2026-11-26 18:31:12
Message-ID: awh4ViI3D411dgQx@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2026-Sep-28, Rafia Sabih wrote:

> I went through this patch and the fix looks good to me. However I see one
> problem with this in the following scenario,
> s1: BEGIN; ALTER INDEX c_a_idx RENAME TO c_renamed; -- c_a_idx attached
> s2: CREATE INDEX pi_new ON p (a); -- now waits (used to complete)
> s1: INSERT INTO c VALUES (1);
> => ERROR: deadlock detected
> Unpatched, both sessions complete.

Yeah, well spotted.

I'm not really sure about the unlocked check plus recheck though. Isn't
it simpler to grab locks on all indexes first, and after the check
release the ones we don't need? As attached. (The isolation test case
now behaves differently)

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Most hackers will be perfectly comfortable conceptualizing users as entropy
sources, so let's move on." (Nathaniel Smith)
https://mail.gnu.org/archive/html/monotone-devel/2007-01/msg00080.html

Attachment Content-Type Size
v3-0001-Recheck-partition-index-attachment-after-locking-.patch text/x-diff 6.6 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-11-26 18:41:16 Re: BUG #17545: Incorrect selectivity for IS NOT DISTINCT FROM and NULLs
Previous Message Álvaro Herrera 2026-11-26 17:18:04 Re: reltuples kept decreasing with each autovacuum run Re: BUG #18773