mirror of https://github.com/citusdata/citus.git
529 lines
32 KiB
Plaintext
529 lines
32 KiB
Plaintext
-- Test queries on a distributed table with shards on the coordinator
|
|
CREATE SCHEMA coordinator_shouldhaveshards;
|
|
SET search_path TO coordinator_shouldhaveshards;
|
|
SET citus.next_shard_id TO 1503000;
|
|
-- idempotently add node to allow this test to run without add_coordinator
|
|
SET client_min_messages TO WARNING;
|
|
SELECT 1 FROM master_add_node('localhost', :master_port, groupid => 0);
|
|
?column?
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
RESET client_min_messages;
|
|
SELECT 1 FROM master_set_node_property('localhost', :master_port, 'shouldhaveshards', true);
|
|
?column?
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
SET citus.shard_replication_factor TO 1;
|
|
CREATE TABLE test (x int, y int);
|
|
SELECT create_distributed_table('test','x', colocate_with := 'none');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM pg_dist_shard JOIN pg_dist_placement USING (shardid)
|
|
WHERE logicalrelid = 'test'::regclass AND groupid = 0;
|
|
count
|
|
---------------------------------------------------------------------
|
|
2
|
|
(1 row)
|
|
|
|
--- enable logging to see which tasks are executed locally
|
|
SET client_min_messages TO LOG;
|
|
SET citus.log_local_commands TO ON;
|
|
-- INSERT..SELECT with COPY under the covers
|
|
INSERT INTO test SELECT s,s FROM generate_series(2,100) s;
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
-- router queries execute locally
|
|
INSERT INTO test VALUES (1, 1);
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.test_1503000 (x, y) VALUES (1, 1)
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
-- multi-shard queries connect to localhost
|
|
SELECT count(*) FROM test;
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
WITH a AS (SELECT * FROM test) SELECT count(*) FROM test;
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
-- multi-shard queries in transaction blocks execute locally
|
|
BEGIN;
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM test;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
END;
|
|
BEGIN;
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM test;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
END;
|
|
-- DDL connects to locahost
|
|
ALTER TABLE test ADD COLUMN z int;
|
|
-- DDL after local execution
|
|
BEGIN;
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
ALTER TABLE test DROP COLUMN z;
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503000, 'coordinator_shouldhaveshards', 'ALTER TABLE test DROP COLUMN z;')
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503003, 'coordinator_shouldhaveshards', 'ALTER TABLE test DROP COLUMN z;')
|
|
ROLLBACK;
|
|
BEGIN;
|
|
ALTER TABLE test DROP COLUMN z;
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503000, 'coordinator_shouldhaveshards', 'ALTER TABLE test DROP COLUMN z;')
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503003, 'coordinator_shouldhaveshards', 'ALTER TABLE test DROP COLUMN z;')
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
END;
|
|
SET citus.shard_count TO 6;
|
|
SET citus.log_remote_commands TO OFF;
|
|
BEGIN;
|
|
SET citus.log_local_commands TO ON;
|
|
CREATE TABLE dist_table (a int);
|
|
INSERT INTO dist_table SELECT * FROM generate_series(1, 100);
|
|
-- trigger local execution
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
-- this should be run locally
|
|
SELECT create_distributed_table('dist_table', 'a', colocate_with := 'none');
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503004, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table (a integer) ');SELECT worker_apply_shard_ddl_command (1503004, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table OWNER TO postgres')
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503007, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table (a integer) ');SELECT worker_apply_shard_ddl_command (1503007, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table OWNER TO postgres')
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
NOTICE: Copying data from local table...
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
NOTICE: copying the data has completed
|
|
DETAIL: The local data in the table is no longer visible, but is still on disk.
|
|
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$coordinator_shouldhaveshards.dist_table$$)
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM dist_table;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.dist_table_1503004 dist_table WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.dist_table_1503007 dist_table WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
ROLLBACK;
|
|
CREATE TABLE dist_table (a int);
|
|
INSERT INTO dist_table SELECT * FROM generate_series(1, 100);
|
|
BEGIN;
|
|
SET citus.log_local_commands TO ON;
|
|
-- trigger local execution
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
-- this should be run locally
|
|
SELECT create_distributed_table('dist_table', 'a', colocate_with := 'none');
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503010, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table (a integer) ');SELECT worker_apply_shard_ddl_command (1503010, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table OWNER TO postgres')
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503013, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table (a integer) ');SELECT worker_apply_shard_ddl_command (1503013, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table OWNER TO postgres')
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
NOTICE: Copying data from local table...
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
NOTICE: copying the data has completed
|
|
DETAIL: The local data in the table is no longer visible, but is still on disk.
|
|
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$coordinator_shouldhaveshards.dist_table$$)
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM dist_table;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.dist_table_1503010 dist_table WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.dist_table_1503013 dist_table WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
ROLLBACK;
|
|
-- repartition queries should work fine
|
|
SET citus.enable_repartition_joins TO ON;
|
|
SELECT count(*) FROM test t1, test t2 WHERE t1.x = t2.y;
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
BEGIN;
|
|
SET citus.enable_repartition_joins TO ON;
|
|
SELECT count(*) FROM test t1, test t2 WHERE t1.x = t2.y;
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
END;
|
|
BEGIN;
|
|
SET citus.enable_repartition_joins TO ON;
|
|
-- trigger local execution
|
|
SELECT y FROM test WHERE x = 1;
|
|
NOTICE: executing the command locally: SELECT y FROM coordinator_shouldhaveshards.test_1503000 test WHERE (x OPERATOR(pg_catalog.=) 1)
|
|
y
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM test t1, test t2 WHERE t1.x = t2.y;
|
|
ERROR: cannot execute command because a local execution has accessed a placement in the transaction
|
|
DETAIL: Some parallel commands cannot be executed if a previous command has already been executed locally
|
|
HINT: Try re-running the transaction with "SET LOCAL citus.enable_local_execution TO OFF;"
|
|
ROLLBACK;
|
|
CREATE TABLE ref (a int, b int);
|
|
SELECT create_reference_table('ref');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE local (x int, y int);
|
|
BEGIN;
|
|
SELECT count(*) FROM test;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
SELECT * FROM ref JOIN local ON (a = x);
|
|
NOTICE: executing the command locally: SELECT ref.a, ref.b, local.x, local.y FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
a | b | x | y
|
|
---------------------------------------------------------------------
|
|
(0 rows)
|
|
|
|
TRUNCATE ref;
|
|
NOTICE: executing the command locally: TRUNCATE TABLE coordinator_shouldhaveshards.ref_xxxxx CASCADE
|
|
ROLLBACK;
|
|
BEGIN;
|
|
SELECT count(*) FROM test;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
TRUNCATE ref;
|
|
NOTICE: executing the command locally: TRUNCATE TABLE coordinator_shouldhaveshards.ref_xxxxx CASCADE
|
|
SELECT * FROM ref JOIN local ON (a = x);
|
|
NOTICE: executing the command locally: SELECT ref.a, ref.b, local.x, local.y FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
a | b | x | y
|
|
---------------------------------------------------------------------
|
|
(0 rows)
|
|
|
|
ROLLBACK;
|
|
BEGIN;
|
|
SELECT count(*) FROM test;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
INSERT INTO ref VALUES (1,2);
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.ref_1503016 (a, b) VALUES (1, 2)
|
|
INSERT INTO local VALUES (1,2);
|
|
SELECT * FROM ref JOIN local ON (a = x);
|
|
NOTICE: executing the command locally: SELECT ref.a, ref.b, local.x, local.y FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
a | b | x | y
|
|
---------------------------------------------------------------------
|
|
1 | 2 | 1 | 2
|
|
(1 row)
|
|
|
|
ROLLBACK;
|
|
set citus.enable_cte_inlining to off;
|
|
BEGIN;
|
|
SELECT count(*) FROM test;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
-- we wont see the modifying cte in this query because we will use local execution and
|
|
-- in postgres we wouldn't see this modifying cte, so it is consistent with postgres.
|
|
WITH a AS (SELECT count(*) FROM test), b AS (INSERT INTO local VALUES (3,2) RETURNING *), c AS (INSERT INTO ref VALUES (3,2) RETURNING *), d AS (SELECT count(*) FROM ref JOIN local ON (a = x)) SELECT * FROM a, b, c, d ORDER BY x,y,a,b;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.ref_1503016 (a, b) VALUES (3, 2) RETURNING a, b
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
NOTICE: executing the command locally: SELECT a.count, b.x, b.y, c.a, c.b, d.count FROM (SELECT intermediate_result.count FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) a, (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) b, (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) c, (SELECT intermediate_result.count FROM read_intermediate_result('XXX_4'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) d ORDER BY b.x, b.y, c.a, c.b
|
|
count | x | y | a | b | count
|
|
---------------------------------------------------------------------
|
|
100 | 3 | 2 | 3 | 2 | 0
|
|
(1 row)
|
|
|
|
TRUNCATE ref;
|
|
NOTICE: executing the command locally: TRUNCATE TABLE coordinator_shouldhaveshards.ref_xxxxx CASCADE
|
|
SELECT * FROM ref JOIN local ON (a = x);
|
|
NOTICE: executing the command locally: SELECT ref.a, ref.b, local.x, local.y FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
a | b | x | y
|
|
---------------------------------------------------------------------
|
|
(0 rows)
|
|
|
|
-- we wont see the modifying cte in this query because we will use local execution and
|
|
-- in postgres we wouldn't see this modifying cte, so it is consistent with postgres.
|
|
WITH a AS (SELECT count(*) FROM test), b AS (INSERT INTO local VALUES (3,2) RETURNING *), c AS (INSERT INTO ref VALUES (3,2) RETURNING *), d AS (SELECT count(*) FROM ref JOIN local ON (a = x)) SELECT * FROM a, b, c, d ORDER BY x,y,a,b;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.ref_1503016 (a, b) VALUES (3, 2) RETURNING a, b
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
NOTICE: executing the command locally: SELECT a.count, b.x, b.y, c.a, c.b, d.count FROM (SELECT intermediate_result.count FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) a, (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) b, (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) c, (SELECT intermediate_result.count FROM read_intermediate_result('XXX_4'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) d ORDER BY b.x, b.y, c.a, c.b
|
|
count | x | y | a | b | count
|
|
---------------------------------------------------------------------
|
|
100 | 3 | 2 | 3 | 2 | 0
|
|
(1 row)
|
|
|
|
ROLLBACK;
|
|
BEGIN;
|
|
-- we wont see the modifying cte in this query because we will use local execution and
|
|
-- in postgres we wouldn't see this modifying cte, so it is consistent with postgres.
|
|
WITH a AS (SELECT count(*) FROM test), b AS (INSERT INTO local VALUES (3,2) RETURNING *), c AS (INSERT INTO ref VALUES (3,2) RETURNING *), d AS (SELECT count(*) FROM ref JOIN local ON (a = x)) SELECT * FROM a, b, c, d ORDER BY x,y,a,b;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.ref_1503016 (a, b) VALUES (3, 2) RETURNING a, b
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
NOTICE: executing the command locally: SELECT a.count, b.x, b.y, c.a, c.b, d.count FROM (SELECT intermediate_result.count FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) a, (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) b, (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) c, (SELECT intermediate_result.count FROM read_intermediate_result('XXX_4'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) d ORDER BY b.x, b.y, c.a, c.b
|
|
count | x | y | a | b | count
|
|
---------------------------------------------------------------------
|
|
100 | 3 | 2 | 3 | 2 | 0
|
|
(1 row)
|
|
|
|
ROLLBACK;
|
|
BEGIN;
|
|
-- we wont see the modifying cte in this query because we will use local execution and
|
|
-- in postgres we wouldn't see this modifying cte, so it is consistent with postgres.
|
|
WITH a AS (SELECT count(*) FROM test), b AS (INSERT INTO local VALUES (3,2) RETURNING *), c AS (INSERT INTO ref SELECT *,* FROM generate_series(1,10) RETURNING *), d AS (SELECT count(*) FROM ref JOIN local ON (a = x)) SELECT * FROM a, b, c, d ORDER BY x,y,a,b;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.ref_1503016 AS citus_table_alias (a, b) SELECT a, b FROM read_intermediate_result('insert_select_XXX_1503016'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer) RETURNING citus_table_alias.a, citus_table_alias.b
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
NOTICE: executing the command locally: SELECT a.count, b.x, b.y, c.a, c.b, d.count FROM (SELECT intermediate_result.count FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) a, (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) b, (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) c, (SELECT intermediate_result.count FROM read_intermediate_result('XXX_4'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) d ORDER BY b.x, b.y, c.a, c.b
|
|
count | x | y | a | b | count
|
|
---------------------------------------------------------------------
|
|
100 | 3 | 2 | 1 | 1 | 0
|
|
100 | 3 | 2 | 2 | 2 | 0
|
|
100 | 3 | 2 | 3 | 3 | 0
|
|
100 | 3 | 2 | 4 | 4 | 0
|
|
100 | 3 | 2 | 5 | 5 | 0
|
|
100 | 3 | 2 | 6 | 6 | 0
|
|
100 | 3 | 2 | 7 | 7 | 0
|
|
100 | 3 | 2 | 8 | 8 | 0
|
|
100 | 3 | 2 | 9 | 9 | 0
|
|
100 | 3 | 2 | 10 | 10 | 0
|
|
(10 rows)
|
|
|
|
ROLLBACK;
|
|
-- same local table reference table tests, but outside a transaction block
|
|
INSERT INTO ref VALUES (1,2);
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.ref_1503016 (a, b) VALUES (1, 2)
|
|
INSERT INTO local VALUES (1,2);
|
|
SELECT * FROM ref JOIN local ON (a = x);
|
|
NOTICE: executing the command locally: SELECT ref.a, ref.b, local.x, local.y FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
a | b | x | y
|
|
---------------------------------------------------------------------
|
|
1 | 2 | 1 | 2
|
|
(1 row)
|
|
|
|
-- we wont see the modifying cte in this query because we will use local execution and
|
|
-- in postgres we wouldn't see this modifying cte, so it is consistent with postgres.
|
|
WITH a AS (SELECT count(*) FROM test), b AS (INSERT INTO local VALUES (3,2) RETURNING *), c AS (INSERT INTO ref VALUES (3,2) RETURNING *), d AS (SELECT count(*) FROM ref JOIN local ON (a = x)) SELECT * FROM a, b, c, d ORDER BY x,y,a,b;
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503000 test WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM coordinator_shouldhaveshards.test_1503003 test WHERE true
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.ref_1503016 (a, b) VALUES (3, 2) RETURNING a, b
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x)))
|
|
NOTICE: executing the command locally: SELECT a.count, b.x, b.y, c.a, c.b, d.count FROM (SELECT intermediate_result.count FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) a, (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) b, (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) c, (SELECT intermediate_result.count FROM read_intermediate_result('XXX_4'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) d ORDER BY b.x, b.y, c.a, c.b
|
|
count | x | y | a | b | count
|
|
---------------------------------------------------------------------
|
|
100 | 3 | 2 | 3 | 2 | 1
|
|
(1 row)
|
|
|
|
-- joins between local tables and distributed tables are disallowed
|
|
CREATE TABLE dist_table(a int);
|
|
ERROR: relation "dist_table" already exists
|
|
SELECT create_distributed_table('dist_table', 'a');
|
|
NOTICE: Copying data from local table...
|
|
NOTICE: copying the data has completed
|
|
DETAIL: The local data in the table is no longer visible, but is still on disk.
|
|
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$coordinator_shouldhaveshards.dist_table$$)
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO dist_table VALUES(1);
|
|
NOTICE: executing the command locally: INSERT INTO coordinator_shouldhaveshards.dist_table_1503017 (a) VALUES (1)
|
|
SELECT * FROM local JOIN dist_table ON (a = x) ORDER BY 1,2,3;
|
|
x | y | a
|
|
---------------------------------------------------------------------
|
|
1 | 2 | 1
|
|
1 | 2 | 1
|
|
3 | 2 | 3
|
|
(3 rows)
|
|
|
|
SELECT * FROM local JOIN dist_table ON (a = x) WHERE a = 1 ORDER BY 1,2,3;
|
|
NOTICE: executing the command locally: SELECT local.x, local.y, dist_table.a FROM ((SELECT local_1.x, local_1.y FROM (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) local_1) local JOIN coordinator_shouldhaveshards.dist_table_1503017 dist_table ON ((dist_table.a OPERATOR(pg_catalog.=) local.x))) WHERE (dist_table.a OPERATOR(pg_catalog.=) 1) ORDER BY local.x, local.y, dist_table.a
|
|
x | y | a
|
|
---------------------------------------------------------------------
|
|
1 | 2 | 1
|
|
1 | 2 | 1
|
|
(2 rows)
|
|
|
|
-- intermediate results are allowed
|
|
WITH cte_1 AS (SELECT * FROM dist_table ORDER BY 1 LIMIT 1)
|
|
SELECT * FROM ref JOIN local ON (a = x) JOIN cte_1 ON (local.x = cte_1.a);
|
|
NOTICE: executing the command locally: SELECT a FROM coordinator_shouldhaveshards.dist_table_1503017 dist_table WHERE true ORDER BY a LIMIT '1'::bigint
|
|
NOTICE: executing the command locally: SELECT a FROM coordinator_shouldhaveshards.dist_table_1503020 dist_table WHERE true ORDER BY a LIMIT '1'::bigint
|
|
NOTICE: executing the command locally: SELECT ref.a, ref.b, local.x, local.y, cte_1.a FROM ((coordinator_shouldhaveshards.ref_1503016 ref JOIN (SELECT local_1.x, local_1.y FROM (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) local_1) local ON ((ref.a OPERATOR(pg_catalog.=) local.x))) JOIN (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) cte_1 ON ((local.x OPERATOR(pg_catalog.=) cte_1.a)))
|
|
a | b | x | y | a
|
|
---------------------------------------------------------------------
|
|
1 | 2 | 1 | 2 | 1
|
|
(1 row)
|
|
|
|
-- full router query with CTE and local
|
|
WITH cte_1 AS (SELECT * FROM ref LIMIT 1)
|
|
SELECT * FROM ref JOIN local ON (a = x) JOIN cte_1 ON (local.x = cte_1.a);
|
|
NOTICE: executing the command locally: WITH cte_1 AS (SELECT ref_1.a, ref_1.b FROM coordinator_shouldhaveshards.ref_1503016 ref_1 LIMIT 1) SELECT ref.a, ref.b, local.x, local.y, cte_1.a, cte_1.b FROM ((coordinator_shouldhaveshards.ref_1503016 ref JOIN coordinator_shouldhaveshards.local ON ((ref.a OPERATOR(pg_catalog.=) local.x))) JOIN cte_1 ON ((local.x OPERATOR(pg_catalog.=) cte_1.a)))
|
|
a | b | x | y | a | b
|
|
---------------------------------------------------------------------
|
|
1 | 2 | 1 | 2 | 1 | 2
|
|
(1 row)
|
|
|
|
DROP TABLE dist_table;
|
|
-- issue #3801
|
|
SET citus.shard_replication_factor TO 2;
|
|
CREATE TABLE dist_table(a int);
|
|
SELECT create_distributed_table('dist_table', 'a');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
BEGIN;
|
|
-- this will use perPlacementQueryStrings, make sure it works correctly with
|
|
-- copying task
|
|
INSERT INTO dist_table SELECT a + 1 FROM dist_table;
|
|
ROLLBACK;
|
|
SET citus.shard_replication_factor TO 1;
|
|
BEGIN;
|
|
SET citus.shard_replication_factor TO 2;
|
|
CREATE TABLE dist_table1(a int);
|
|
-- this will use queryStringList, make sure it works correctly with
|
|
-- copying task
|
|
SELECT create_distributed_table('dist_table1', 'a');
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503029, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table1 (a integer) ');SELECT worker_apply_shard_ddl_command (1503029, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table1 OWNER TO postgres')
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503031, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table1 (a integer) ');SELECT worker_apply_shard_ddl_command (1503031, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table1 OWNER TO postgres')
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503032, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table1 (a integer) ');SELECT worker_apply_shard_ddl_command (1503032, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table1 OWNER TO postgres')
|
|
NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1503034, 'coordinator_shouldhaveshards', 'CREATE TABLE coordinator_shouldhaveshards.dist_table1 (a integer) ');SELECT worker_apply_shard_ddl_command (1503034, 'coordinator_shouldhaveshards', 'ALTER TABLE coordinator_shouldhaveshards.dist_table1 OWNER TO postgres')
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
ROLLBACK;
|
|
RESET citus.enable_cte_inlining;
|
|
CREATE table ref_table(x int, y int);
|
|
-- this will be replicated to the coordinator because of add_coordinator test
|
|
SELECT create_reference_table('ref_table');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
TRUNCATE TABLE test;
|
|
BEGIN;
|
|
INSERT INTO test SELECT *, * FROM generate_series(1, 100);
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
INSERT INTO ref_table SELECT *, * FROM generate_series(1, 100);
|
|
NOTICE: executing the copy locally for shard xxxxx
|
|
SELECT COUNT(*) FROM test JOIN ref_table USING(x);
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinator_shouldhaveshards.test_1503000 test JOIN coordinator_shouldhaveshards.ref_table_1503035 ref_table ON ((test.x OPERATOR(pg_catalog.=) ref_table.x))) WHERE true
|
|
NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinator_shouldhaveshards.test_1503003 test JOIN coordinator_shouldhaveshards.ref_table_1503035 ref_table ON ((test.x OPERATOR(pg_catalog.=) ref_table.x))) WHERE true
|
|
count
|
|
---------------------------------------------------------------------
|
|
100
|
|
(1 row)
|
|
|
|
ROLLBACK;
|
|
\set VERBOSITY terse
|
|
DROP TABLE ref_table;
|
|
NOTICE: executing the command locally: DROP TABLE IF EXISTS coordinator_shouldhaveshards.ref_table_xxxxx CASCADE
|
|
DELETE FROM test;
|
|
DROP TABLE test;
|
|
DROP TABLE dist_table;
|
|
DROP TABLE ref;
|
|
NOTICE: executing the command locally: DROP TABLE IF EXISTS coordinator_shouldhaveshards.ref_xxxxx CASCADE
|
|
DROP SCHEMA coordinator_shouldhaveshards CASCADE;
|
|
NOTICE: drop cascades to table local
|
|
SELECT 1 FROM master_set_node_property('localhost', :master_port, 'shouldhaveshards', false);
|
|
?column?
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|