Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Tender Wang <tndrwang@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2024-06-28T11:27:17Z
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
On 2024-Jun-12, Tender Wang wrote: > I think what you said above. I feel that we need that "tp_pkey" is a > partition > of the partitioned index "t_a_idx". For example, below statement: > > test=# alter table tp drop constraint tp_pkey; > ERROR: cannot drop index tp_pkey because index t_a_idx requires it > HINT: You can drop index t_a_idx instead. > > If "tp_pkey" is not a partition of "t_a_idx", the primary key "tp_pkey" can > be dropped. I guess you could also fix this by adding a PK constraint to the parent table, so that the situation is consistent in the other direction. Here's a proposed patch for master only. It turns all three situations being reported into ereport(ERROR); in one case I have an XXX comment, because we have an alternative when attaching a partition that already has a PK to a partitioned table that has a non-PK index: just create a separate index in the partition. But that would cause slowness, which is probably undesirable. I'm inclined to just remove the XXX comment, but if anyone has other thoughts, they are welcome. I add an errhint() to one of these new errors, but I'm undecided about that idea --- should we add errhint() to all three messages, or none? We can't do this in back branches, of course (incl. 17 at this point), because that might break existing applications, which means we need to adjust behavior in some other way, probably similar to what Tender Wang suggested, namely just don't crash on detach, or something like that. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/