1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-03 09:13:20 +03:00

Fix ALTER TABLE's scheduling rules for AT_AddConstraint subcommands.

Commit 1281a5c90 rearranged the logic in this area rather drastically,
and it broke the case of adding a foreign key constraint in the same
ALTER that adds the pkey or unique constraint it depends on.  While
self-referential fkeys are surely a pretty niche case, this used to
work so we shouldn't break it.

To fix, reorganize the scheduling rules in ATParseTransformCmd so
that a transformed AT_AddConstraint subcommand will be delayed into
a later pass in all cases, not only when it's been spit out as a
side-effect of parsing some other command type.

Also tweak the logic so that we won't run ATParseTransformCmd twice
while doing this.  It seems to work even without that, but it's
surely wasting cycles to do so.

Per bug #16589 from Jeremy Evans.  Back-patch to v13 where the new
code was introduced.

Discussion: https://postgr.es/m/16589-31c8d981ca503896@postgresql.org
This commit is contained in:
Tom Lane
2020-08-22 12:34:17 -04:00
parent c3a288649e
commit 5b02d68e75
3 changed files with 135 additions and 66 deletions

View File

@@ -2252,6 +2252,20 @@ ALTER TABLE ataddindex
\d ataddindex
DROP TABLE ataddindex;
CREATE TABLE ataddindex(id int, ref_id int);
ALTER TABLE ataddindex
ADD PRIMARY KEY (id),
ADD FOREIGN KEY (ref_id) REFERENCES ataddindex;
\d ataddindex
DROP TABLE ataddindex;
CREATE TABLE ataddindex(id int, ref_id int);
ALTER TABLE ataddindex
ADD UNIQUE (id),
ADD FOREIGN KEY (ref_id) REFERENCES ataddindex (id);
\d ataddindex
DROP TABLE ataddindex;
-- unsupported constraint types for partitioned tables
CREATE TABLE partitioned (
a int,