From 5ec5e6afaab91556f80bdef94c64339efe1acc0b Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Mon, 28 Feb 2022 15:15:39 +0300 Subject: [PATCH] Add more tests --- .../regress/expected/function_propagation.out | 155 ++++++++++++++++++ src/test/regress/sql/function_propagation.sql | 101 ++++++++++++ 2 files changed, 256 insertions(+) diff --git a/src/test/regress/expected/function_propagation.out b/src/test/regress/expected/function_propagation.out index 7d2037a0b89..d8fbb1d3ec5 100644 --- a/src/test/regress/expected/function_propagation.out +++ b/src/test/regress/expected/function_propagation.out @@ -771,6 +771,161 @@ SELECT * FROM table_2_for_rule; (1 row) ROLLBACK; +-- Show that functions as partitioning functions are supported +BEGIN; + CREATE OR REPLACE FUNCTION non_sense_func_for_partitioning(int) + RETURNS int + LANGUAGE plpgsql IMMUTABLE AS + $$ + BEGIN + return 1; + END; + $$; + -- Functions shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.non_sense_func_for_partitioning'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- +(0 rows) + + CREATE TABLE partitioned_table_to_test_func_prop(id INT, a INT) PARTITION BY RANGE (non_sense_func_for_partitioning(id)); + SELECT create_distributed_table('partitioned_table_to_test_func_prop', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + + -- Show that function is distributed after distributing the table + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.non_sense_func_for_partitioning'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- + (function,"{function_propagation_schema,non_sense_func_for_partitioning}",{integer}) +(1 row) + +COMMIT; +-- Function should be marked as distributed on the worker after committing changes +SELECT * FROM run_command_on_workers($$SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.non_sense_func_for_partitioning'::regproc::oid;$$) ORDER BY 1,2; + nodename | nodeport | success | result +--------------------------------------------------------------------- + localhost | 57637 | t | (function,"{function_propagation_schema,non_sense_func_for_partitioning}",{integer}) + localhost | 57638 | t | (function,"{function_propagation_schema,non_sense_func_for_partitioning}",{integer}) +(2 rows) + +-- Test function dependency on citus local table +BEGIN; + CREATE OR REPLACE FUNCTION func_in_transaction_for_local_table() + RETURNS int + LANGUAGE plpgsql AS + $$ + BEGIN + return 1; + END; + $$; + -- Function shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_in_transaction_for_local_table'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- +(0 rows) + + CREATE TABLE citus_local_table_to_test_func(l1 int DEFAULT func_in_transaction_for_local_table()); + SELECT 1 FROM master_add_node('localhost', :master_port, groupid => 0); +NOTICE: localhost:xxxxx is the coordinator and already contains metadata, skipping syncing the metadata + ?column? +--------------------------------------------------------------------- + 1 +(1 row) + + SELECT citus_add_local_table_to_metadata('citus_local_table_to_test_func'); + citus_add_local_table_to_metadata +--------------------------------------------------------------------- + +(1 row) + + -- Function should be marked as distributed after distributing the table that depends on it + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_in_transaction_for_local_table'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- + (function,"{function_propagation_schema,func_in_transaction_for_local_table}",{}) +(1 row) + +ROLLBACK; +BEGIN; + CREATE OR REPLACE FUNCTION exclude_bool_func() + RETURNS boolean + LANGUAGE plpgsql IMMUTABLE AS + $$ + BEGIN + return true; + END; + $$; + -- Functions shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.exclude_bool_func'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- +(0 rows) + + CREATE TABLE exclusion_func_prop_table (id int, EXCLUDE USING btree (id WITH =) WHERE (exclude_bool_func())); + SELECT create_distributed_table('exclusion_func_prop_table', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + + -- Function should be marked as distributed after distributing the table that depends on it + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.exclude_bool_func'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- + (function,"{function_propagation_schema,exclude_bool_func}",{}) +(1 row) + +COMMIT; +-- Function should be marked as distributed on the worker after committing changes +SELECT * FROM run_command_on_workers($$SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.exclude_bool_func'::regproc::oid;$$) ORDER BY 1,2; + nodename | nodeport | success | result +--------------------------------------------------------------------- + localhost | 57637 | t | (function,"{function_propagation_schema,exclude_bool_func}",{}) + localhost | 57638 | t | (function,"{function_propagation_schema,exclude_bool_func}",{}) +(2 rows) + +-- Show that having a function dependency for index also works +BEGIN; + CREATE OR REPLACE FUNCTION func_for_index_predicate(col_1 int) + RETURNS boolean + LANGUAGE plpgsql IMMUTABLE AS + $$ + BEGIN + return col_1 > 5; + END; + $$; + -- Functions shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_for_index_predicate'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- +(0 rows) + + CREATE TABLE table_to_check_func_index_dep (id int, col_2 int); + CREATE INDEX on table_to_check_func_index_dep(col_2) WHERE (func_for_index_predicate(col_2)); + SELECT create_distributed_table('table_to_check_func_index_dep', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + + -- Function should be marked as distributed after distributing the table that depends on it + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_for_index_predicate'::regproc::oid; + pg_identify_object_as_address +--------------------------------------------------------------------- + (function,"{function_propagation_schema,func_for_index_predicate}",{integer}) +(1 row) + +COMMIT; +-- Function should be marked as distributed on the worker after committing changes +SELECT * FROM run_command_on_workers($$SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_for_index_predicate'::regproc::oid;$$) ORDER BY 1,2; + nodename | nodeport | success | result +--------------------------------------------------------------------- + localhost | 57637 | t | (function,"{function_propagation_schema,func_for_index_predicate}",{integer}) + localhost | 57638 | t | (function,"{function_propagation_schema,func_for_index_predicate}",{integer}) +(2 rows) + 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 1309fa2d17c..cf4c4e2b3ef 100644 --- a/src/test/regress/sql/function_propagation.sql +++ b/src/test/regress/sql/function_propagation.sql @@ -497,6 +497,107 @@ BEGIN; SELECT * FROM table_2_for_rule; ROLLBACK; + +-- Show that functions as partitioning functions are supported +BEGIN; + + CREATE OR REPLACE FUNCTION non_sense_func_for_partitioning(int) + RETURNS int + LANGUAGE plpgsql IMMUTABLE AS + $$ + BEGIN + return 1; + END; + $$; + + -- Functions shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.non_sense_func_for_partitioning'::regproc::oid; + + CREATE TABLE partitioned_table_to_test_func_prop(id INT, a INT) PARTITION BY RANGE (non_sense_func_for_partitioning(id)); + + SELECT create_distributed_table('partitioned_table_to_test_func_prop', 'id'); + + -- Show that function is distributed after distributing the table + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.non_sense_func_for_partitioning'::regproc::oid; +COMMIT; + +-- Function should be marked as distributed on the worker after committing changes +SELECT * FROM run_command_on_workers($$SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.non_sense_func_for_partitioning'::regproc::oid;$$) ORDER BY 1,2; + + +-- Test function dependency on citus local table +BEGIN; + CREATE OR REPLACE FUNCTION func_in_transaction_for_local_table() + RETURNS int + LANGUAGE plpgsql AS + $$ + BEGIN + return 1; + END; + $$; + + -- Function shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_in_transaction_for_local_table'::regproc::oid; + + CREATE TABLE citus_local_table_to_test_func(l1 int DEFAULT func_in_transaction_for_local_table()); + SELECT 1 FROM master_add_node('localhost', :master_port, groupid => 0); + SELECT citus_add_local_table_to_metadata('citus_local_table_to_test_func'); + + -- Function should be marked as distributed after distributing the table that depends on it + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_in_transaction_for_local_table'::regproc::oid; +ROLLBACK; + + +BEGIN; + CREATE OR REPLACE FUNCTION exclude_bool_func() + RETURNS boolean + LANGUAGE plpgsql IMMUTABLE AS + $$ + BEGIN + return true; + END; + $$; + + -- Functions shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.exclude_bool_func'::regproc::oid; + + CREATE TABLE exclusion_func_prop_table (id int, EXCLUDE USING btree (id WITH =) WHERE (exclude_bool_func())); + SELECT create_distributed_table('exclusion_func_prop_table', 'id'); + + -- Function should be marked as distributed after distributing the table that depends on it + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.exclude_bool_func'::regproc::oid; +COMMIT; + +-- Function should be marked as distributed on the worker after committing changes +SELECT * FROM run_command_on_workers($$SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.exclude_bool_func'::regproc::oid;$$) ORDER BY 1,2; + + +-- Show that having a function dependency for index also works +BEGIN; + CREATE OR REPLACE FUNCTION func_for_index_predicate(col_1 int) + RETURNS boolean + LANGUAGE plpgsql IMMUTABLE AS + $$ + BEGIN + return col_1 > 5; + END; + $$; + + -- Functions shouldn't be propagated within transaction + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_for_index_predicate'::regproc::oid; + + CREATE TABLE table_to_check_func_index_dep (id int, col_2 int); + CREATE INDEX on table_to_check_func_index_dep(col_2) WHERE (func_for_index_predicate(col_2)); + + SELECT create_distributed_table('table_to_check_func_index_dep', 'id'); + + -- Function should be marked as distributed after distributing the table that depends on it + SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_for_index_predicate'::regproc::oid; +COMMIT; + +-- Function should be marked as distributed on the worker after committing changes +SELECT * FROM run_command_on_workers($$SELECT pg_identify_object_as_address(classid, objid, objsubid) from citus.pg_dist_object where objid = 'function_propagation_schema.func_for_index_predicate'::regproc::oid;$$) ORDER BY 1,2; + RESET search_path; SET client_min_messages TO WARNING; DROP SCHEMA function_propagation_schema CASCADE;