Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Burak Velioglu committed Feb 28, 2022
1 parent aee452a commit 5ec5e6a
Show file tree
Hide file tree
Showing 2 changed files with 256 additions and 0 deletions.
155 changes: 155 additions & 0 deletions src/test/regress/expected/function_propagation.out
Original file line number Diff line number Diff line change
Expand Up @@ -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;
101 changes: 101 additions & 0 deletions src/test/regress/sql/function_propagation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 5ec5e6a

Please sign in to comment.