mirror of
https://github.com/postgres/postgres.git
synced 2025-11-26 23:43:30 +03:00
Move most of the error checking for foreign-key constraints out of
parse analysis and into the execution code (in tablecmds.c). This eliminates a lot of unreasonably complex code that needed to have two or more execution paths in case it was dealing with a not-yet-created table column vs. an already-existing one. The execution code is always dealing with already-created tables and so needs only one case. This also eliminates some potential race conditions (the table wasn't locked between parse analysis and execution), makes it easy to fix the gripe about wrong referenced-column names generating a misleading error message, and lets us easily add a dependency from the foreign-key constraint to the unique index that it requires the referenced table to have. (Cf. complaint from Kris Jurka 12-Sep-2002 on pgsql-bugs.) Also, third try at building a deletion mechanism that is not sensitive to the order in which pg_depend entries are visited. Adding the above- mentioned dependency exposed the folly of what dependency.c had been doing: it failed for cases where B depends on C while both auto-depend on A. Dropping A should succeed in this case, but was failing if C happened to be visited before B. It appears the only solution is two separate walks over the dependency tree.
This commit is contained in:
@@ -322,7 +322,7 @@ ERROR: ALTER TABLE: column "c" referenced in foreign key constraint does not ex
|
||||
-- Try (and fail) to add constraint due to invalide destination columns explicitly given
|
||||
ALTER TABLE tmp3 add constraint tmpconstr foreign key(a) references tmp2(b) match full;
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: UNIQUE constraint matching given keys for referenced table "tmp2" not found
|
||||
ERROR: ALTER TABLE: column "b" referenced in foreign key constraint does not exist
|
||||
-- Try (and fail) to add constraint due to invalid data
|
||||
ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
@@ -908,10 +908,10 @@ NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: ALTER TABLE: column "........pg.dropped.1........" referenced in foreign key constraint does not exist
|
||||
alter table atacc2 add foreign key (id) references atacc1(a);
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: UNIQUE constraint matching given keys for referenced table "atacc1" not found
|
||||
ERROR: ALTER TABLE: column "a" referenced in foreign key constraint does not exist
|
||||
alter table atacc2 add foreign key (id) references atacc1("........pg.dropped.1........");
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: UNIQUE constraint matching given keys for referenced table "atacc1" not found
|
||||
ERROR: ALTER TABLE: column "........pg.dropped.1........" referenced in foreign key constraint does not exist
|
||||
drop table atacc2;
|
||||
create index "testing_idx" on atacc1(a);
|
||||
ERROR: DefineIndex: attribute "a" not found
|
||||
|
||||
@@ -692,7 +692,7 @@ NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: CREATE TABLE: column "ftest2" referenced in foreign key constraint does not exist
|
||||
CREATE TABLE FKTABLE_FAIL2 ( ftest1 int, CONSTRAINT fkfail1 FOREIGN KEY (ftest1) REFERENCES PKTABLE(ptest2));
|
||||
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: UNIQUE constraint matching given keys for referenced table "pktable" not found
|
||||
ERROR: CREATE TABLE: column "ptest2" referenced in foreign key constraint does not exist
|
||||
DROP TABLE FKTABLE_FAIL1;
|
||||
ERROR: table "fktable_fail1" does not exist
|
||||
DROP TABLE FKTABLE_FAIL2;
|
||||
|
||||
@@ -548,7 +548,6 @@ DROP VIEW atestv1;
|
||||
DROP VIEW atestv2;
|
||||
-- this should cascade to drop atestv4
|
||||
DROP VIEW atestv3 CASCADE;
|
||||
NOTICE: Drop cascades to rule _RETURN on view atestv3
|
||||
NOTICE: Drop cascades to rule _RETURN on view atestv4
|
||||
NOTICE: Drop cascades to view atestv4
|
||||
-- this should complain "does not exist"
|
||||
|
||||
Reference in New Issue
Block a user