From 9e9c345d8f1d3ee19b8ac851c9d0c20a0f4c2b4c Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 4 Mar 2020 11:21:38 +0300 Subject: [PATCH] update existing tests --- .../failure_multi_shard_update_delete.out | 3 + .../foreign_key_restriction_enforcement.out | 9 +++ .../foreign_key_to_reference_table.out | 64 +++++++++++++++++++ .../regress/expected/multi_foreign_key.out | 12 ++-- .../multi_replicate_reference_table.out | 6 ++ .../mx_foreign_key_to_reference_table.out | 6 ++ 6 files changed, 95 insertions(+), 5 deletions(-) diff --git a/src/test/regress/expected/failure_multi_shard_update_delete.out b/src/test/regress/expected/failure_multi_shard_update_delete.out index cebd7f8c6..3decb8f07 100644 --- a/src/test/regress/expected/failure_multi_shard_update_delete.out +++ b/src/test/regress/expected/failure_multi_shard_update_delete.out @@ -24,6 +24,9 @@ SELECT create_distributed_table('t1', 'a'); (1 row) SELECT create_reference_table('r1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- diff --git a/src/test/regress/expected/foreign_key_restriction_enforcement.out b/src/test/regress/expected/foreign_key_restriction_enforcement.out index 261e00096..b29945ce0 100644 --- a/src/test/regress/expected/foreign_key_restriction_enforcement.out +++ b/src/test/regress/expected/foreign_key_restriction_enforcement.out @@ -1271,6 +1271,9 @@ BEGIN; CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i; SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key NOTICE: Copying data from local table... create_reference_table --------------------------------------------------------------------- @@ -1295,6 +1298,9 @@ BEGIN; CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i; SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key NOTICE: Copying data from local table... create_reference_table --------------------------------------------------------------------- @@ -1316,6 +1322,9 @@ BEGIN; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- diff --git a/src/test/regress/expected/foreign_key_to_reference_table.out b/src/test/regress/expected/foreign_key_to_reference_table.out index 9f30cd236..6d4abbe29 100644 --- a/src/test/regress/expected/foreign_key_to_reference_table.out +++ b/src/test/regress/expected/foreign_key_to_reference_table.out @@ -745,6 +745,9 @@ CREATE TABLE referencing_table(id int, ref_id int DEFAULT -1, FOREIGN KEY (ref_i INSERT INTO referenced_table VALUES (1,1), (2,2), (3,3); INSERT INTO referencing_table VALUES (1,1), (2,2), (3,3); SELECT create_reference_table('referenced_table'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key NOTICE: Copying data from local table... create_reference_table --------------------------------------------------------------------- @@ -859,12 +862,18 @@ CREATE TABLE referenced_table(test_column int, test_column2 int, PRIMARY KEY(tes CREATE TABLE referenced_table2(test_column int, test_column2 int, PRIMARY KEY(test_column2)); CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE, FOREIGN KEY (id) REFERENCES referenced_table2(test_column2) ON DELETE CASCADE); SELECT create_reference_table('referenced_table'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- (1 row) SELECT create_reference_table('referenced_table2'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -985,6 +994,7 @@ CREATE TABLE referenced_table2(test_column int, test_column2 int, PRIMARY KEY(te CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE); BEGIN; SELECT create_reference_table('referenced_table'); +WARNING: should not create foreign key constraint in this way create_reference_table --------------------------------------------------------------------- @@ -1125,6 +1135,12 @@ CREATE TABLE referenced_table(test_column int, test_column2 int UNIQUE, PRIMARY CREATE TABLE referencing_table(id int PRIMARY KEY, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE); CREATE TABLE referencing_table2(id int, ref_id int, FOREIGN KEY (ref_id) REFERENCES referenced_table(test_column2) ON DELETE CASCADE, FOREIGN KEY (id) REFERENCES referencing_table(id) ON DELETE CASCADE); SELECT create_reference_table('referenced_table'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1304,6 +1320,9 @@ BEGIN; CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i; SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key NOTICE: Copying data from local table... create_reference_table --------------------------------------------------------------------- @@ -1321,6 +1340,9 @@ BEGIN; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1341,6 +1363,9 @@ COMMIT; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1401,6 +1426,9 @@ ERROR: table "test_table_1" does not exist CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1426,6 +1454,9 @@ BEGIN; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1451,6 +1482,9 @@ DROP TABLE test_table_1, test_table_2; CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1475,6 +1509,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); BEGIN; SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1499,6 +1536,9 @@ DROP TABLE test_table_1, test_table_2; CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1524,6 +1564,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); BEGIN; SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1549,6 +1592,9 @@ DROP TABLE test_table_1, test_table_2; CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1585,6 +1631,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); BEGIN; SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1611,6 +1660,9 @@ DROP TABLE test_table_1, test_table_2; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1636,6 +1688,9 @@ DROP TABLE test_table_1, test_table_2; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1664,6 +1719,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); BEGIN; SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1690,6 +1748,9 @@ DROP TABLE test_table_1, test_table_2; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- @@ -1722,6 +1783,9 @@ DROP TABLE test_table_1, test_table_2; CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); SELECT create_reference_table('test_table_1'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- diff --git a/src/test/regress/expected/multi_foreign_key.out b/src/test/regress/expected/multi_foreign_key.out index 2b612124e..614326d0c 100644 --- a/src/test/regress/expected/multi_foreign_key.out +++ b/src/test/regress/expected/multi_foreign_key.out @@ -836,7 +836,7 @@ SELECT create_distributed_table('referenced_by_reference_table', 'id'); CREATE TABLE reference_table(id int, referencing_column int REFERENCES referenced_by_reference_table(id)); SELECT create_reference_table('reference_table'); ERROR: cannot create foreign key constraint since foreign keys from reference tables to distributed tables are not supported -DETAIL: A reference table can only have reference keys to other reference tables +DETAIL: A reference table can only have reference keys to other reference tables or a local table in coordinator -- test foreign key creation on CREATE TABLE from + to reference table DROP TABLE reference_table; CREATE TABLE reference_table(id int PRIMARY KEY, referencing_column int); @@ -860,7 +860,8 @@ NOTICE: drop cascades to constraint reference_table_second_referencing_column_f CREATE TABLE reference_table(id int, referencing_column int REFERENCES referenced_local_table(id)); SELECT create_reference_table('reference_table'); ERROR: cannot create foreign key constraint -DETAIL: Referenced table must be a distributed table or a reference table. +DETAIL: Local table having a foreign key constraint to another local table cannot be upgraded to a reference table +HINT: To define foreign key constraint from a reference table to a local table, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key -- test foreign key creation on CREATE TABLE on self referencing reference table CREATE TABLE self_referencing_reference_table( id int, @@ -886,7 +887,7 @@ SELECT create_reference_table('reference_table'); ALTER TABLE reference_table ADD CONSTRAINT fk FOREIGN KEY(referencing_column) REFERENCES referenced_by_reference_table(id); ERROR: cannot create foreign key constraint since foreign keys from reference tables to distributed tables are not supported -DETAIL: A reference table can only have reference keys to other reference tables +DETAIL: A reference table can only have reference keys to other reference tables or a local table in coordinator -- test foreign key creation on ALTER TABLE to reference table CREATE TABLE references_to_reference_table(id int, referencing_column int); SELECT create_distributed_table('references_to_reference_table', 'referencing_column'); @@ -919,8 +920,9 @@ SELECT create_reference_table('reference_table'); (1 row) ALTER TABLE reference_table ADD CONSTRAINT fk FOREIGN KEY(referencing_column) REFERENCES referenced_local_table(id); -ERROR: cannot create foreign key constraint -DETAIL: Referenced table must be a distributed table or a reference table. +ERROR: cannot ADD/DROP foreign key constraint +DETAIL: Referenced table must be a distributed table or a reference table or a local table in coordinator. +HINT: To ADD/DROP foreign constraint between reference tables and coordinator local tables, consider adding coordinator to pg_dist_node as well. -- test foreign key creation on ALTER TABLE on self referencing reference table DROP TABLE self_referencing_reference_table; CREATE TABLE self_referencing_reference_table( diff --git a/src/test/regress/expected/multi_replicate_reference_table.out b/src/test/regress/expected/multi_replicate_reference_table.out index 714e8353e..60e8d43da 100644 --- a/src/test/regress/expected/multi_replicate_reference_table.out +++ b/src/test/regress/expected/multi_replicate_reference_table.out @@ -661,6 +661,12 @@ CREATE TABLE ref_table_3(id int primary key, v int references ref_table_2(id)); SELECT create_reference_table('ref_table_1'), create_reference_table('ref_table_2'), create_reference_table('ref_table_3'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table | create_reference_table | create_reference_table --------------------------------------------------------------------- | | diff --git a/src/test/regress/expected/mx_foreign_key_to_reference_table.out b/src/test/regress/expected/mx_foreign_key_to_reference_table.out index d99500a13..657ad4682 100644 --- a/src/test/regress/expected/mx_foreign_key_to_reference_table.out +++ b/src/test/regress/expected/mx_foreign_key_to_reference_table.out @@ -30,12 +30,18 @@ CREATE TABLE referencing_table(id int, ref_id int); ALTER TABLE referencing_table ADD CONSTRAINT fkey_ref FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE; ALTER TABLE referencing_table ADD CONSTRAINT foreign_key_2 FOREIGN KEY (id) REFERENCES referenced_table2(test_column2) ON DELETE CASCADE; SELECT create_reference_table('referenced_table'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table --------------------------------------------------------------------- (1 row) SELECT create_reference_table('referenced_table2'); +WARNING: should not create foreign key constraint in this way +DETAIL: Local table referenced by another local table should not be upgraded to a reference table +HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key create_reference_table ---------------------------------------------------------------------