Add test for undistributed partitioned table

talha_tes1
Ahmet Gedemenli 2021-10-21 20:06:08 +03:00
parent 02d77fb04e
commit eed4c913ed
2 changed files with 104 additions and 3 deletions

View File

@ -531,6 +531,69 @@ SELECT logicalrelid, autoconverted FROM pg_dist_partition
auto_local_table_2 | f
(2 rows)
-- test with partitioned tables
CREATE TABLE partitioned_table_1 (a int unique) partition by range(a);
CREATE TABLE partitioned_table_1_1 partition of partitioned_table_1 FOR VALUES FROM (0) TO (10);
CREATE TABLE partitioned_table_2 (a int unique) partition by range(a);
CREATE TABLE partitioned_table_2_1 partition of partitioned_table_2 FOR VALUES FROM (0) TO (10);
CREATE TABLE ref_fkey_to_partitioned (a int unique references partitioned_table_1(a), b int unique references partitioned_table_2(a));
SELECT create_reference_table('ref_fkey_to_partitioned');
create_reference_table
---------------------------------------------------------------------
(1 row)
-- verify that partitioned tables and partitions are converted automatically
SELECT logicalrelid, autoconverted FROM pg_dist_partition
WHERE logicalrelid IN ('partitioned_table_1'::regclass,
'partitioned_table_1_1'::regclass,
'partitioned_table_2'::regclass,
'partitioned_table_2_1'::regclass)
ORDER BY logicalrelid;
logicalrelid | autoconverted
---------------------------------------------------------------------
partitioned_table_1_1 | t
partitioned_table_1 | t
partitioned_table_2_1 | t
partitioned_table_2 | t
(4 rows)
BEGIN;
SELECT citus_add_local_table_to_metadata('partitioned_table_2');
citus_add_local_table_to_metadata
---------------------------------------------------------------------
(1 row)
-- verify that they are now marked as auto-converted = false
SELECT logicalrelid, autoconverted FROM pg_dist_partition
WHERE logicalrelid IN ('partitioned_table_1'::regclass,
'partitioned_table_1_1'::regclass,
'partitioned_table_2'::regclass,
'partitioned_table_2_1'::regclass)
ORDER BY logicalrelid;
logicalrelid | autoconverted
---------------------------------------------------------------------
partitioned_table_1_1 | f
partitioned_table_1 | f
partitioned_table_2_1 | f
partitioned_table_2 | f
(4 rows)
ROLLBACK;
-- now they should be undistributed
DROP TABLE ref_fkey_to_partitioned;
-- verify that they are undistributed
SELECT logicalrelid, autoconverted FROM pg_dist_partition
WHERE logicalrelid IN ('partitioned_table_1'::regclass,
'partitioned_table_1_1'::regclass,
'partitioned_table_2'::regclass,
'partitioned_table_2_1'::regclass)
ORDER BY logicalrelid;
logicalrelid | autoconverted
---------------------------------------------------------------------
(0 rows)
-- a single drop table cascades into multiple undistributes
DROP TABLE IF EXISTS citus_local_table_1, citus_local_table_2, citus_local_table_3, citus_local_table_2, reference_table_1;
CREATE TABLE reference_table_1(r1 int UNIQUE, r2 int);
@ -568,9 +631,9 @@ ALTER TABLE reference_table_1 OWNER TO another_user;
SELECT run_command_on_placements('reference_table_1', 'ALTER TABLE %s OWNER TO another_user');
run_command_on_placements
---------------------------------------------------------------------
(localhost,57636,1810045,t,"ALTER TABLE")
(localhost,57637,1810045,t,"ALTER TABLE")
(localhost,57638,1810045,t,"ALTER TABLE")
(localhost,57636,1810050,t,"ALTER TABLE")
(localhost,57637,1810050,t,"ALTER TABLE")
(localhost,57638,1810050,t,"ALTER TABLE")
(3 rows)
SET citus.enable_ddl_propagation to ON;

View File

@ -249,6 +249,44 @@ SELECT logicalrelid, autoconverted FROM pg_dist_partition
'auto_local_table_2'::regclass)
ORDER BY logicalrelid;
-- test with partitioned tables
CREATE TABLE partitioned_table_1 (a int unique) partition by range(a);
CREATE TABLE partitioned_table_1_1 partition of partitioned_table_1 FOR VALUES FROM (0) TO (10);
CREATE TABLE partitioned_table_2 (a int unique) partition by range(a);
CREATE TABLE partitioned_table_2_1 partition of partitioned_table_2 FOR VALUES FROM (0) TO (10);
CREATE TABLE ref_fkey_to_partitioned (a int unique references partitioned_table_1(a), b int unique references partitioned_table_2(a));
SELECT create_reference_table('ref_fkey_to_partitioned');
-- verify that partitioned tables and partitions are converted automatically
SELECT logicalrelid, autoconverted FROM pg_dist_partition
WHERE logicalrelid IN ('partitioned_table_1'::regclass,
'partitioned_table_1_1'::regclass,
'partitioned_table_2'::regclass,
'partitioned_table_2_1'::regclass)
ORDER BY logicalrelid;
BEGIN;
SELECT citus_add_local_table_to_metadata('partitioned_table_2');
-- verify that they are now marked as auto-converted = false
SELECT logicalrelid, autoconverted FROM pg_dist_partition
WHERE logicalrelid IN ('partitioned_table_1'::regclass,
'partitioned_table_1_1'::regclass,
'partitioned_table_2'::regclass,
'partitioned_table_2_1'::regclass)
ORDER BY logicalrelid;
ROLLBACK;
-- now they should be undistributed
DROP TABLE ref_fkey_to_partitioned;
-- verify that they are undistributed
SELECT logicalrelid, autoconverted FROM pg_dist_partition
WHERE logicalrelid IN ('partitioned_table_1'::regclass,
'partitioned_table_1_1'::regclass,
'partitioned_table_2'::regclass,
'partitioned_table_2_1'::regclass)
ORDER BY logicalrelid;
-- a single drop table cascades into multiple undistributes
DROP TABLE IF EXISTS citus_local_table_1, citus_local_table_2, citus_local_table_3, citus_local_table_2, reference_table_1;
CREATE TABLE reference_table_1(r1 int UNIQUE, r2 int);