citus/src/test/regress/expected/multi_mx_call_0.out

338 lines
12 KiB
Plaintext

-- Test passing off CALL to mx workers
create schema multi_mx_call;
set search_path to multi_mx_call, public;
-- Create worker-local tables to test procedure calls were routed
set citus.shard_replication_factor to 2;
set citus.replication_model to 'statement';
-- This table requires specific settings, create before getting into things
create table mx_call_dist_table_replica(id int, val int);
select create_distributed_table('mx_call_dist_table_replica', 'id');
create_distributed_table
--------------------------
(1 row)
insert into mx_call_dist_table_replica values (9,1),(8,2),(7,3),(6,4),(5,5);
set citus.shard_replication_factor to 1;
set citus.replication_model to 'streaming';
--
-- Create tables and procedures we want to use in tests
--
create table mx_call_dist_table_1(id int, val int);
select create_distributed_table('mx_call_dist_table_1', 'id');
create_distributed_table
--------------------------
(1 row)
insert into mx_call_dist_table_1 values (3,1),(4,5),(9,2),(6,5),(3,5);
create table mx_call_dist_table_2(id int, val int);
select create_distributed_table('mx_call_dist_table_2', 'id');
create_distributed_table
--------------------------
(1 row)
insert into mx_call_dist_table_2 values (1,1),(1,2),(2,2),(3,3),(3,4);
create table mx_call_dist_table_ref(id int, val int);
select create_reference_table('mx_call_dist_table_ref');
create_reference_table
------------------------
(1 row)
insert into mx_call_dist_table_ref values (2,7),(1,8),(2,8),(1,8),(2,8);
create type mx_call_enum as enum ('A', 'S', 'D', 'F');
create table mx_call_dist_table_enum(id int, key mx_call_enum);
select create_distributed_table('mx_call_dist_table_enum', 'key');
create_distributed_table
--------------------------
(1 row)
insert into mx_call_dist_table_enum values (1,'S'),(2,'A'),(3,'D'),(4,'F');
CREATE PROCEDURE mx_call_proc(x int, INOUT y int)
LANGUAGE plpgsql AS $$
BEGIN
-- groupid is 0 in coordinator and non-zero in workers, so by using it here
-- we make sure the procedure is being executed in the worker.
y := x + (select case groupid when 0 then 1 else 0 end from pg_dist_local_group);
-- we also make sure that we can run distributed queries in the procedures
-- that are routed to the workers.
y := y + (select sum(t1.val + t2.val) from multi_mx_call.mx_call_dist_table_1 t1 join multi_mx_call.mx_call_dist_table_2 t2 on t1.id = t2.id);
END;$$;
ERROR: syntax error at or near "PROCEDURE"
LINE 1: CREATE PROCEDURE mx_call_proc(x int, INOUT y int)
^
-- create another procedure which verifies:
-- 1. we work fine with multiple return columns
-- 2. we work fine in combination with custom types
CREATE PROCEDURE mx_call_proc_custom_types(INOUT x mx_call_enum, INOUT y mx_call_enum)
LANGUAGE plpgsql AS $$
BEGIN
y := x;
x := (select case groupid when 0 then 'F' else 'S' end from pg_dist_local_group);
END;$$;
ERROR: syntax error at or near "PROCEDURE"
LINE 1: CREATE PROCEDURE mx_call_proc_custom_types(INOUT x mx_call_e...
^
-- Test that undistributed procedures have no issue executing
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
call multi_mx_call.mx_call_proc_custom_types('S', 'A');
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc_custom_types('S', 'A');
^
-- Same for unqualified names
call mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call mx_call_proc(2, 0);
^
call mx_call_proc_custom_types('S', 'A');
ERROR: syntax error at or near "call"
LINE 1: call mx_call_proc_custom_types('S', 'A');
^
-- Mark both procedures as distributed ...
select create_distributed_function('mx_call_proc(int,int)');
ERROR: function "mx_call_proc(int,int)" does not exist
LINE 1: select create_distributed_function('mx_call_proc(int,int)');
^
select create_distributed_function('mx_call_proc_custom_types(mx_call_enum,mx_call_enum)');
ERROR: function "mx_call_proc_custom_types(mx_call_enum,mx_call_enum)" does not exist
LINE 1: select create_distributed_function('mx_call_proc_custom_type...
^
-- We still don't route them to the workers, because they aren't
-- colocated with any distributed tables.
SET client_min_messages TO DEBUG1;
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
call multi_mx_call.mx_call_proc_custom_types('S', 'A');
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc_custom_types('S', 'A');
^
-- Mark them as colocated with a table. Now we should route them to workers.
select colocate_proc_with_table('mx_call_proc', 'mx_call_dist_table_1'::regclass, 1);
colocate_proc_with_table
--------------------------
(1 row)
select colocate_proc_with_table('mx_call_proc_custom_types', 'mx_call_dist_table_enum'::regclass, 1);
colocate_proc_with_table
--------------------------
(1 row)
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
call multi_mx_call.mx_call_proc_custom_types('S', 'A');
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc_custom_types('S', 'A');
^
call mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call mx_call_proc(2, 0);
^
call mx_call_proc_custom_types('S', 'A');
ERROR: syntax error at or near "call"
LINE 1: call mx_call_proc_custom_types('S', 'A');
^
-- We don't allow distributing calls inside transactions
begin;
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
commit;
-- Drop the table colocated with mx_call_proc_custom_types. Now it shouldn't
-- be routed to workers anymore.
SET client_min_messages TO NOTICE;
drop table mx_call_dist_table_enum;
SET client_min_messages TO DEBUG1;
call multi_mx_call.mx_call_proc_custom_types('S', 'A');
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc_custom_types('S', 'A');
^
-- Make sure we do bounds checking on distributed argument index
-- This also tests that we have cache invalidation for pg_dist_object updates
select colocate_proc_with_table('mx_call_proc', 'mx_call_dist_table_1'::regclass, -1);
colocate_proc_with_table
--------------------------
(1 row)
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
select colocate_proc_with_table('mx_call_proc', 'mx_call_dist_table_1'::regclass, 2);
colocate_proc_with_table
--------------------------
(1 row)
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
-- We don't currently support colocating with reference tables
select colocate_proc_with_table('mx_call_proc', 'mx_call_dist_table_ref'::regclass, 1);
colocate_proc_with_table
--------------------------
(1 row)
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
-- We don't currently support colocating with replicated tables
select colocate_proc_with_table('mx_call_proc', 'mx_call_dist_table_replica'::regclass, 1);
colocate_proc_with_table
--------------------------
(1 row)
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
SET client_min_messages TO NOTICE;
drop table mx_call_dist_table_replica;
SET client_min_messages TO DEBUG1;
select colocate_proc_with_table('mx_call_proc', 'mx_call_dist_table_1'::regclass, 1);
colocate_proc_with_table
--------------------------
(1 row)
-- Test that we handle transactional constructs correctly inside a procedure
-- that is routed to the workers.
CREATE PROCEDURE mx_call_proc_tx(x int) LANGUAGE plpgsql AS $$
BEGIN
INSERT INTO multi_mx_call.mx_call_dist_table_1 VALUES (x, -1), (x+1, 4);
COMMIT;
UPDATE multi_mx_call.mx_call_dist_table_1 SET val = val+1 WHERE id >= x;
ROLLBACK;
-- Now do the final update!
UPDATE multi_mx_call.mx_call_dist_table_1 SET val = val-1 WHERE id >= x;
END;$$;
ERROR: syntax error at or near "PROCEDURE"
LINE 1: CREATE PROCEDURE mx_call_proc_tx(x int) LANGUAGE plpgsql AS ...
^
-- before distribution ...
CALL multi_mx_call.mx_call_proc_tx(10);
ERROR: syntax error at or near "CALL"
LINE 1: CALL multi_mx_call.mx_call_proc_tx(10);
^
-- after distribution ...
select create_distributed_function('mx_call_proc_tx(int)', '$1', 'mx_call_dist_table_1');
ERROR: function "mx_call_proc_tx(int)" does not exist
LINE 1: select create_distributed_function('mx_call_proc_tx(int)', '...
^
CALL multi_mx_call.mx_call_proc_tx(20);
ERROR: syntax error at or near "CALL"
LINE 1: CALL multi_mx_call.mx_call_proc_tx(20);
^
SELECT id, val FROM mx_call_dist_table_1 ORDER BY id, val;
id | val
----+-----
3 | 1
3 | 5
4 | 5
6 | 5
9 | 2
(5 rows)
-- Test that we properly propagate errors raised from procedures.
CREATE PROCEDURE mx_call_proc_raise(x int) LANGUAGE plpgsql AS $$
BEGIN
RAISE WARNING 'warning';
RAISE EXCEPTION 'error';
END;$$;
ERROR: syntax error at or near "PROCEDURE"
LINE 1: CREATE PROCEDURE mx_call_proc_raise(x int) LANGUAGE plpgsql ...
^
select create_distributed_function('mx_call_proc_raise(int)', '$1', 'mx_call_dist_table_1');
ERROR: function "mx_call_proc_raise(int)" does not exist
LINE 1: select create_distributed_function('mx_call_proc_raise(int)'...
^
call multi_mx_call.mx_call_proc_raise(2);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc_raise(2);
^
-- Test that we don't propagate to non-metadata worker nodes
select stop_metadata_sync_to_node('localhost', :worker_1_port);
stop_metadata_sync_to_node
----------------------------
(1 row)
select stop_metadata_sync_to_node('localhost', :worker_2_port);
stop_metadata_sync_to_node
----------------------------
(1 row)
call multi_mx_call.mx_call_proc(2, 0);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, 0);
^
SET client_min_messages TO NOTICE;
select start_metadata_sync_to_node('localhost', :worker_1_port);
start_metadata_sync_to_node
-----------------------------
(1 row)
select start_metadata_sync_to_node('localhost', :worker_2_port);
start_metadata_sync_to_node
-----------------------------
(1 row)
-- stop_metadata_sync_to_node()/start_metadata_sync_to_node() might make
-- worker backend caches inconsistent. Reconnect to coordinator to use
-- new worker connections, hence new backends.
\c - - - :master_port
SET search_path to multi_mx_call, public;
SET client_min_messages TO DEBUG1;
--
-- Test non-const parameter values
--
CREATE FUNCTION mx_call_add(int, int) RETURNS int
AS 'select $1 + $2;' LANGUAGE SQL IMMUTABLE;
SELECT create_distributed_function('mx_call_add(int,int)', '$1');
DEBUG: switching to sequential query execution mode
DETAIL: A distributed function is created. To make sure subsequent commands see the type correctly we need to make sure to use only one connection for all future commands
create_distributed_function
-----------------------------
(1 row)
-- non-const distribution parameters cannot be pushed down
call multi_mx_call.mx_call_proc(2, mx_call_add(3, 4));
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(2, mx_call_add(3, 4));
^
-- non-const parameter can be pushed down
call multi_mx_call.mx_call_proc(multi_mx_call.mx_call_add(3, 4), 2);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(multi_mx_call.mx_call_add(3,...
^
-- volatile parameter cannot be pushed down
call multi_mx_call.mx_call_proc(floor(random())::int, 2);
ERROR: syntax error at or near "call"
LINE 1: call multi_mx_call.mx_call_proc(floor(random())::int, 2);
^
reset client_min_messages;
\set VERBOSITY terse
drop schema multi_mx_call cascade;
NOTICE: drop cascades to 5 other objects