From bb5962ee797729b1cd33e9d8339a2b1c863ca11e Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Thu, 28 Jan 2021 14:18:06 +0300 Subject: [PATCH] Early error out when creating citus local from a temp table (#4592) --- .../commands/citus_add_local_table_to_metadata.c | 15 +++++++++++++++ src/test/regress/expected/citus_local_tables.out | 6 ++++++ src/test/regress/sql/citus_local_tables.sql | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c index 06c7e4064..9939b8856 100644 --- a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c +++ b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c @@ -362,6 +362,21 @@ ErrorIfUnsupportedCitusLocalTableKind(Oid relationId) "tables and foreign tables can be added to citus metadata ", relationName))); } + + if (get_rel_persistence(relationId) == RELPERSISTENCE_TEMP) + { + /* + * Currently, we use citus local tables only to support foreign keys + * between local tables and reference tables. Citus already doesn't + * support creating reference tables from temp tables. + * So now we are creating a citus local table from a temp table that + * has a foreign key from/to a reference table with persistent storage. + * In that case, we want to give the same error as postgres would do. + */ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("constraints on temporary tables may reference only " + "temporary tables"))); + } } diff --git a/src/test/regress/expected/citus_local_tables.out b/src/test/regress/expected/citus_local_tables.out index f580c7995..b1d2a1f22 100644 --- a/src/test/regress/expected/citus_local_tables.out +++ b/src/test/regress/expected/citus_local_tables.out @@ -50,6 +50,12 @@ SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0); (1 row) RESET client_min_messages; +BEGIN; + CREATE TEMPORARY TABLE temp_table (a int); + -- errors out as we don't support creating citus local table from a temp table + SELECT citus_add_local_table_to_metadata('temp_table'); +ERROR: constraints on temporary tables may reference only temporary tables +ROLLBACK; -- creating citus local table having no data initially would work SELECT citus_add_local_table_to_metadata('citus_local_table_1'); citus_add_local_table_to_metadata diff --git a/src/test/regress/sql/citus_local_tables.sql b/src/test/regress/sql/citus_local_tables.sql index 89e8356d7..1cfa75d27 100644 --- a/src/test/regress/sql/citus_local_tables.sql +++ b/src/test/regress/sql/citus_local_tables.sql @@ -40,6 +40,12 @@ set client_min_messages to ERROR; SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0); RESET client_min_messages; +BEGIN; + CREATE TEMPORARY TABLE temp_table (a int); + -- errors out as we don't support creating citus local table from a temp table + SELECT citus_add_local_table_to_metadata('temp_table'); +ROLLBACK; + -- creating citus local table having no data initially would work SELECT citus_add_local_table_to_metadata('citus_local_table_1');