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: Michael Paquier <michael@paquier.xyz>
Cc: Tender Wang <tndrwang@gmail.com>, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2024-06-27T18:41:47Z
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
On 2024-Jun-12, Michael Paquier wrote: > On Wed, Jun 12, 2024 at 01:49:32PM +0800, Tender Wang wrote: > > 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. > > The 4th command is I think incorrect to attach "t_a_idx" to "tp"'s > primary key index because "t" does not have an equivalent entry in > pg_constraint. So that does not address the actual issue. Actually, the partition index is attached to the parent index already at CREATE UNIQUE INDEX, so it's the third line that's the problem (but what you say is true too if the user says CREATE UNIQUE INDEX ON ONLY parent). I tend to agree that a good, consistent fix for this would be to forbid a PK in a partition from becoming a child of a non-constraint index in the parent ... A few ereport(ERROR)s sprinkled in various places might be sufficient in the master branch, but perhaps we shouldn't disallow it in stable branches because that might be problematic for existing apps; and I suspect that we'd need to install protections in pg_upgrade to fix databases from earlier branches being upgraded with the given hierarchy (or just prevent the upgrade in --check and tell the users to fix it.) -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/