From: | Tender Wang <tndrwang(at)gmail(dot)com> |
---|---|
To: | Alexander Lakhin <exclusion(at)gmail(dot)com> |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Subject: | Re: BUG #18628: Race condition during attach/detach partition breaks constraints of partition having foreign key |
Date: | 2024-09-24 11:20:02 |
Message-ID: | CAHewXNkUoKRT+G=O9EB7-zxx807sRfC63h=n_AJrMc8zayr5PQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Alexander Lakhin <exclusion(at)gmail(dot)com> 于2024年9月24日周二 19:00写道:
> 22.09.2024 17:00, PG Bug reporting form wrote:
> > The following script:
> > ...
> > ends up with:
> > ERROR: could not find ON INSERT check triggers of foreign key constraint
> > 16409
>
> I'm sorry, I' was too hasty to untangle those queries. Now I see that
> this error can be produced with this serial script:
> CREATE TABLE pt (id int PRIMARY KEY, rid int,
> FOREIGN KEY (rid) REFERENCES pt(id))
> PARTITION BY LIST (id);
>
> CREATE TABLE p1 PARTITION OF pt FOR VALUES IN (1);
> ALTER TABLE pt DETACH PARTITION p1;
> -- p1 gets a constraint:
> -- "pt_rid_fkey" FOREIGN KEY (rid) REFERENCES pt(id)
>
> CREATE TABLE p2 PARTITION OF pt FOR VALUES IN (2);
> -- CloneFkReferenced() -> addFkRecurseReferenced() clones the above
> -- constraint and creates another one:
> -- conname: p1_rid_fkey, conrelid: id of p1, confrelid: id of p2,
> -- conparentid: id of the above constraint
> -- (\d+ p2 doesn't show this constraint due to conparentid != 0)
>
> ALTER TABLE pt ATTACH PARTITION p1 FOR VALUES IN (1);
> -- p1 attached with no constraints added or removed
>
> ALTER TABLE pt DETACH PARTITION p1;
> -- DetachPartitionFinalize() gets the p1_rid_fkey constraint with
> -- RelationGetFKeyList(partRel) and then fails to find INSERT trigger for
> -- it, because the constraint has only DELETE and UPDATE triggers linked
> -- to the p2 relation.
>
> ERROR: could not find ON INSERT check triggers of foreign key constraint
> 16410
>
> Alvaro, could you please take a look at this?
>
>
I haven't looked at it in detail, but I have a feeling that this issue has
a very close relation to the issue in [1].
Now we don't do well when the partition table references itself.
--
Thanks,
Tender Wang
https://www.openpie.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2024-09-24 11:23:33 | Re: BUG #18628: Race condition during attach/detach partition breaks constraints of partition having foreign key |
Previous Message | Alexander Lakhin | 2024-09-24 11:00:00 | Re: BUG #18628: Race condition during attach/detach partition breaks constraints of partition having foreign key |