Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert
Tender Wang <tndrwang@gmail.com>
From: Tender Wang <tndrwang@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2024-06-12T05:49:32Z
Lists: pgsql-bugs
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix ALTER TABLE DETACH for inconsistent indexes
- d0054432d480 12.20 landed
- 83917791385a 18.0 landed
- 66aaa7a71841 14.13 landed
- 4ae09c59d6f5 15.8 landed
- 30ca4e1ab1ff 17.0 landed
- 05748256939b 13.16 landed
- 00a40e33c0a4 16.4 landed
Attachments
- v1-0001-Fix-assert-failure-when-detach-partition.patch (application/octet-stream) patch v1-0001
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/