Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert
Date: 2024-06-12 05:49:32
Message-ID: CAHewXNnZhGT1eM58-=5MQQ=moJ4hjqd3aDscxPSmB+SzwN3oUQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi, all

I found another crash case as below:
CREATE TABLE t (a integer) PARTITION BY RANGE (a);
CREATE TABLE tp (a integer PRIMARY KEY);
CREATE UNIQUE INDEX t_a_idx ON t (a);
ALTER TABLE t ATTACH PARTITION tp FOR VALUES FROM (0) TO (1000);
ALTER TABLE t DETACH PARTITION tp;

If index of parent is not created by adding constraint, it will trigger
assert fail.

I look through the DetachPartitionFinalize(). The logic of detach indexes
finds a pg_inherits tuple,
then it goes to detach the constraint between parent and child. But in
AttachPartitionEnsureIndexes(),
it check whether constraint of parent is valid or not. If it is valid, then
the code will build constraint
connection between parent and child.

I think we can do this check in DetachPartitionFinalize(). We skip to
detach the constraint if parent actually
does not have one. I try to fix theses issue in attached patch.

--
Tender Wang
OpenPie: https://en.openpie.com/

Attachment Content-Type Size
v1-0001-Fix-assert-failure-when-detach-partition.patch application/octet-stream 6.6 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2024-06-12 06:12:31 Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert
Previous Message David G. Johnston 2024-06-12 02:18:27 Re: BUG #18502: Upsert on view returns 42P10 error when condition is an expression