diff --git a/src/test/regress/expected/function_propagation.out b/src/test/regress/expected/function_propagation.out index d9bd88d96..5231ff1d1 100644 --- a/src/test/regress/expected/function_propagation.out +++ b/src/test/regress/expected/function_propagation.out @@ -1188,7 +1188,7 @@ SELECT distribution_argument_index, colocationid, force_delegation FROM pg_catal | | (1 row) --- Show that causing circular dependency via functions are not allowed +-- Show that causing circular dependency via functions and default values are not allowed CREATE TABLE table_1_for_circ_dep(id int); select create_distributed_table('table_1_for_circ_dep','id'); create_distributed_table @@ -1223,6 +1223,41 @@ $$; ALTER TABLE table_1_for_circ_dep ADD COLUMN col_2 int default func_2_for_circ_dep(NULL::table_2_for_circ_dep); ERROR: Citus can not handle circular dependencies between distributed objects DETAIL: "table table_1_for_circ_dep" circularly depends itself, resolve circular dependency first +-- Show that causing circular dependency via functions and constraints are not allowed +CREATE TABLE table_1_for_circ_dep_2(id int, col_1 int); +select create_distributed_table('table_1_for_circ_dep_2','id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE OR REPLACE FUNCTION func_1_for_circ_dep_2(param_1 int, param_2 table_1_for_circ_dep_2) +RETURNS boolean +LANGUAGE plpgsql AS +$$ +BEGIN + return param_1 > 5; +END; +$$; +CREATE TABLE table_2_for_circ_dep_2(id int, col_1 int check (func_1_for_circ_dep_2(col_1, NULL::table_1_for_circ_dep_2))); +select create_distributed_table('table_2_for_circ_dep_2','id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE OR REPLACE FUNCTION func_2_for_circ_dep_2(param_1 int, param_2 table_2_for_circ_dep_2) +RETURNS boolean +LANGUAGE plpgsql AS +$$ +BEGIN + return param_1 > 5; +END; +$$; +-- It should error out due to circular dependency +ALTER TABLE table_1_for_circ_dep_2 ADD CONSTRAINT check_const_for_circ check (func_2_for_circ_dep_2(col_1, NULL::table_2_for_circ_dep_2)); +ERROR: Citus can not handle circular dependencies between distributed objects +DETAIL: "table table_1_for_circ_dep_2" circularly depends itself, resolve circular dependency first RESET search_path; SET client_min_messages TO WARNING; DROP SCHEMA function_propagation_schema CASCADE; diff --git a/src/test/regress/sql/function_propagation.sql b/src/test/regress/sql/function_propagation.sql index 4ac09328f..f278269a1 100644 --- a/src/test/regress/sql/function_propagation.sql +++ b/src/test/regress/sql/function_propagation.sql @@ -757,7 +757,7 @@ SELECT create_distributed_function('func_to_colocate(int)'); SELECT distribution_argument_index, colocationid, force_delegation FROM pg_catalog.pg_dist_object WHERE objid = 'func_to_colocate'::regproc; --- Show that causing circular dependency via functions are not allowed +-- Show that causing circular dependency via functions and default values are not allowed CREATE TABLE table_1_for_circ_dep(id int); select create_distributed_table('table_1_for_circ_dep','id'); @@ -785,6 +785,34 @@ $$; ALTER TABLE table_1_for_circ_dep ADD COLUMN col_2 int default func_2_for_circ_dep(NULL::table_2_for_circ_dep); +-- Show that causing circular dependency via functions and constraints are not allowed +CREATE TABLE table_1_for_circ_dep_2(id int, col_1 int); +select create_distributed_table('table_1_for_circ_dep_2','id'); + +CREATE OR REPLACE FUNCTION func_1_for_circ_dep_2(param_1 int, param_2 table_1_for_circ_dep_2) +RETURNS boolean +LANGUAGE plpgsql AS +$$ +BEGIN + return param_1 > 5; +END; +$$; + +CREATE TABLE table_2_for_circ_dep_2(id int, col_1 int check (func_1_for_circ_dep_2(col_1, NULL::table_1_for_circ_dep_2))); + +select create_distributed_table('table_2_for_circ_dep_2','id'); +CREATE OR REPLACE FUNCTION func_2_for_circ_dep_2(param_1 int, param_2 table_2_for_circ_dep_2) +RETURNS boolean +LANGUAGE plpgsql AS +$$ +BEGIN + return param_1 > 5; +END; +$$; + +-- It should error out due to circular dependency +ALTER TABLE table_1_for_circ_dep_2 ADD CONSTRAINT check_const_for_circ check (func_2_for_circ_dep_2(col_1, NULL::table_2_for_circ_dep_2)); + RESET search_path; SET client_min_messages TO WARNING; DROP SCHEMA function_propagation_schema CASCADE;