From b20615cbbe921defe4e26b065201c3e3b8b850f0 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 27 Jan 2021 17:59:06 +0300 Subject: [PATCH] Advise dropping foreign key in addition to create_reference_table hint (#4590) --- src/backend/distributed/commands/foreign_constraint.c | 3 ++- src/test/regress/expected/multi_foreign_key.out | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backend/distributed/commands/foreign_constraint.c b/src/backend/distributed/commands/foreign_constraint.c index 36300cbff..cee90475a 100644 --- a/src/backend/distributed/commands/foreign_constraint.c +++ b/src/backend/distributed/commands/foreign_constraint.c @@ -48,7 +48,8 @@ #define USE_CREATE_REFERENCE_TABLE_HINT \ "You could use SELECT create_reference_table('%s') " \ - "to replicate the referenced table to all nodes" + "to replicate the referenced table to all nodes or " \ + "consider dropping the foreign key" typedef bool (*CheckRelationFunc)(Oid); diff --git a/src/test/regress/expected/multi_foreign_key.out b/src/test/regress/expected/multi_foreign_key.out index 4cc52d894..d3a58d412 100644 --- a/src/test/regress/expected/multi_foreign_key.out +++ b/src/test/regress/expected/multi_foreign_key.out @@ -861,7 +861,7 @@ CREATE TABLE reference_table(id int, referencing_column int REFERENCES reference SELECT create_reference_table('reference_table'); ERROR: referenced table "referenced_local_table" must be a distributed table or a reference table DETAIL: To enforce foreign keys, the referencing and referenced rows need to be stored on the same node. -HINT: You could use SELECT create_reference_table('referenced_local_table') to replicate the referenced table to all nodes +HINT: You could use SELECT create_reference_table('referenced_local_table') to replicate the referenced table to all nodes or consider dropping the foreign key -- test foreign key creation on CREATE TABLE on self referencing reference table CREATE TABLE self_referencing_reference_table( id int, @@ -922,7 +922,7 @@ SELECT create_reference_table('reference_table'); ALTER TABLE reference_table ADD CONSTRAINT fk FOREIGN KEY(referencing_column) REFERENCES referenced_local_table(id); ERROR: referenced table "referenced_local_table" must be a distributed table or a reference table DETAIL: To enforce foreign keys, the referencing and referenced rows need to be stored on the same node. -HINT: You could use SELECT create_reference_table('referenced_local_table') to replicate the referenced table to all nodes +HINT: You could use SELECT create_reference_table('referenced_local_table') to replicate the referenced table to all nodes or consider dropping the foreign key -- test foreign key creation on ALTER TABLE on self referencing reference table DROP TABLE self_referencing_reference_table; CREATE TABLE self_referencing_reference_table(