From ea5a85bc91861095661697226ae307218604463a Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 6 Jan 2021 02:44:13 +0300 Subject: [PATCH] fixup! Update existing tests & Add more tests --- .../multi_foreign_key_relation_graph.out | 26 +++++++++++++++++++ .../sql/multi_foreign_key_relation_graph.sql | 23 ++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/test/regress/expected/multi_foreign_key_relation_graph.out b/src/test/regress/expected/multi_foreign_key_relation_graph.out index 9bda65c72..81e3bc2d9 100644 --- a/src/test/regress/expected/multi_foreign_key_relation_graph.out +++ b/src/test/regress/expected/multi_foreign_key_relation_graph.out @@ -982,6 +982,32 @@ ORDER BY tablename; reference_table_4 (8 rows) +CREATE TABLE local_partitioned_table_1 (col_1 INT UNIQUE, col_2 INT) PARTITION BY RANGE (col_1); +DEBUG: CREATE TABLE / UNIQUE will create implicit index "local_partitioned_table_1_col_1_key" for table "local_partitioned_table_1" +CREATE TABLE local_partitioned_table_2 (col_1 INT UNIQUE, col_2 INT) PARTITION BY RANGE (col_1); +DEBUG: CREATE TABLE / UNIQUE will create implicit index "local_partitioned_table_2_col_1_key" for table "local_partitioned_table_2" +-- in below two show that attaching a partition doesn't invalidate +-- foreign key cache as parent table isn't involved in any foreign +-- key relationship +CREATE TABLE local_partitioned_table_1_100_200 PARTITION OF local_partitioned_table_1 FOR VALUES FROM (100) TO (200); +DEBUG: CREATE TABLE / UNIQUE will create implicit index "local_partitioned_table_1_100_200_col_1_key" for table "local_partitioned_table_1_100_200" +CREATE TABLE local_partitioned_table_2_100_200 (col_1 INT UNIQUE, col_2 INT); +DEBUG: CREATE TABLE / UNIQUE will create implicit index "local_partitioned_table_2_100_200_col_1_key" for table "local_partitioned_table_2_100_200" +ALTER TABLE local_partitioned_table_2 ATTACH PARTITION local_partitioned_table_2_100_200 FOR VALUES FROM (100) TO (200); +DEBUG: verifying table "local_partitioned_table_2_100_200" +-- define foreign key between parent tables +ALTER TABLE local_partitioned_table_1 ADD CONSTRAINT fkey_10 FOREIGN KEY (col_1) REFERENCES local_partitioned_table_2(col_1); +DEBUG: DDL command invalidates foreign key graph +-- in below two show that attaching partition invalidates foreign +-- key cache as parent table is involved in a foreign key relationship +CREATE TABLE local_partitioned_table_2_200_300 PARTITION OF local_partitioned_table_2 FOR VALUES FROM (200) TO (300); +DEBUG: CREATE TABLE / UNIQUE will create implicit index "local_partitioned_table_2_200_300_col_1_key" for table "local_partitioned_table_2_200_300" +DEBUG: DDL command invalidates foreign key graph +CREATE TABLE local_partitioned_table_1_300_400 (col_1 INT UNIQUE, col_2 INT); +DEBUG: CREATE TABLE / UNIQUE will create implicit index "local_partitioned_table_1_300_400_col_1_key" for table "local_partitioned_table_1_300_400" +ALTER TABLE local_partitioned_table_1 ATTACH PARTITION local_partitioned_table_1_300_400 FOR VALUES FROM (300) TO (400); +DEBUG: verifying table "local_partitioned_table_1_300_400" +DEBUG: DDL command invalidates foreign key graph set client_min_messages to error; SET search_path TO public; DROP SCHEMA fkey_graph CASCADE; diff --git a/src/test/regress/sql/multi_foreign_key_relation_graph.sql b/src/test/regress/sql/multi_foreign_key_relation_graph.sql index cb23f8da2..74a9052f0 100644 --- a/src/test/regress/sql/multi_foreign_key_relation_graph.sql +++ b/src/test/regress/sql/multi_foreign_key_relation_graph.sql @@ -447,6 +447,29 @@ SELECT oid::regclass::text AS tablename FROM get_foreign_key_connected_relations('partitioned_table_1_300_400') AS f(oid oid) ORDER BY tablename; +CREATE TABLE local_partitioned_table_1 (col_1 INT UNIQUE, col_2 INT) PARTITION BY RANGE (col_1); +CREATE TABLE local_partitioned_table_2 (col_1 INT UNIQUE, col_2 INT) PARTITION BY RANGE (col_1); + +-- in below two show that attaching a partition doesn't invalidate +-- foreign key cache as parent table isn't involved in any foreign +-- key relationship + +CREATE TABLE local_partitioned_table_1_100_200 PARTITION OF local_partitioned_table_1 FOR VALUES FROM (100) TO (200); + +CREATE TABLE local_partitioned_table_2_100_200 (col_1 INT UNIQUE, col_2 INT); +ALTER TABLE local_partitioned_table_2 ATTACH PARTITION local_partitioned_table_2_100_200 FOR VALUES FROM (100) TO (200); + +-- define foreign key between parent tables +ALTER TABLE local_partitioned_table_1 ADD CONSTRAINT fkey_10 FOREIGN KEY (col_1) REFERENCES local_partitioned_table_2(col_1); + +-- in below two show that attaching partition invalidates foreign +-- key cache as parent table is involved in a foreign key relationship + +CREATE TABLE local_partitioned_table_2_200_300 PARTITION OF local_partitioned_table_2 FOR VALUES FROM (200) TO (300); + +CREATE TABLE local_partitioned_table_1_300_400 (col_1 INT UNIQUE, col_2 INT); +ALTER TABLE local_partitioned_table_1 ATTACH PARTITION local_partitioned_table_1_300_400 FOR VALUES FROM (300) TO (400); + set client_min_messages to error; SET search_path TO public;