-- -- Distributed Partitioned Table Tests -- SET citus.next_shard_id TO 1660000; SET citus.shard_count TO 4; SET citus.shard_replication_factor TO 1; -- print major version number for version-specific tests SHOW server_version \gset SELECT substring(:'server_version', '\d+')::int AS server_version; server_version ---------------- 9 (1 row) -- -- Distributed Partitioned Table Creation Tests -- -- 1-) Distributing partitioned table -- create partitioned table CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test(id int, time date) PARTITION ... ^ CREATE TABLE partitioning_hash_test(id int, subid int) PARTITION BY HASH(subid); ERROR: syntax error at or near "PARTITION" LINE 1: ...E TABLE partitioning_hash_test(id int, subid int) PARTITION ... ^ -- create its partitions CREATE TABLE partitioning_test_2009 PARTITION OF partitioning_test FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_2009 PARTITION OF partitionin... ^ CREATE TABLE partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_2010 PARTITION OF partitionin... ^ CREATE TABLE partitioning_hash_test_0 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_hash_test_0 PARTITION OF partition... ^ CREATE TABLE partitioning_hash_test_1 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_hash_test_1 PARTITION OF partition... ^ -- load some data and distribute tables INSERT INTO partitioning_test VALUES (1, '2009-06-06'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES (1, '2009-06-06'); ^ INSERT INTO partitioning_test VALUES (2, '2010-07-07'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES (2, '2010-07-07'); ^ INSERT INTO partitioning_test_2009 VALUES (3, '2009-09-09'); ERROR: relation "partitioning_test_2009" does not exist LINE 1: INSERT INTO partitioning_test_2009 VALUES (3, '2009-09-09'); ^ INSERT INTO partitioning_test_2010 VALUES (4, '2010-03-03'); ERROR: relation "partitioning_test_2010" does not exist LINE 1: INSERT INTO partitioning_test_2010 VALUES (4, '2010-03-03'); ^ INSERT INTO partitioning_hash_test VALUES (1, 2); ERROR: relation "partitioning_hash_test" does not exist LINE 1: INSERT INTO partitioning_hash_test VALUES (1, 2); ^ INSERT INTO partitioning_hash_test VALUES (2, 13); ERROR: relation "partitioning_hash_test" does not exist LINE 1: INSERT INTO partitioning_hash_test VALUES (2, 13); ^ INSERT INTO partitioning_hash_test VALUES (3, 7); ERROR: relation "partitioning_hash_test" does not exist LINE 1: INSERT INTO partitioning_hash_test VALUES (3, 7); ^ INSERT INTO partitioning_hash_test VALUES (4, 4); ERROR: relation "partitioning_hash_test" does not exist LINE 1: INSERT INTO partitioning_hash_test VALUES (4, 4); ^ -- distribute partitioned table SELECT create_distributed_table('partitioning_test', 'id'); ERROR: relation "partitioning_test" does not exist LINE 1: SELECT create_distributed_table('partitioning_test', 'id'); ^ SELECT create_distributed_table('partitioning_hash_test', 'id'); ERROR: relation "partitioning_hash_test" does not exist LINE 1: SELECT create_distributed_table('partitioning_hash_test', 'i... ^ -- see the data is loaded to shards SELECT * FROM partitioning_test ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test ORDER BY 1; ^ SELECT * FROM partitioning_hash_test ORDER BY 1; ERROR: relation "partitioning_hash_test" does not exist LINE 1: SELECT * FROM partitioning_hash_test ORDER BY 1; ^ -- see partitioned table and its partitions are distributed SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 6: logicalrelid IN ('partitioning_test', 'partitioning_test_20... ^ SELECT logicalrelid, count(*) FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') GROUP BY logicalrelid ORDER BY 1,2; ERROR: relation "partitioning_test" does not exist LINE 4: WHERE logicalrelid IN ('partitioning_test', 'partitioning_t... ^ SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid IN ('partitioning_hash_test', 'partitioning_hash_test_0', 'partitioning_hash_test_1') ORDER BY 1; ERROR: relation "partitioning_hash_test" does not exist LINE 6: logicalrelid IN ('partitioning_hash_test', 'partitioning_ha... ^ SELECT logicalrelid, count(*) FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_hash_test', 'partitioning_hash_test_0', 'partitioning_hash_test_1') GROUP BY logicalrelid ORDER BY 1,2; ERROR: relation "partitioning_hash_test" does not exist LINE 4: WHERE logicalrelid IN ('partitioning_hash_test', 'partition... ^ -- 2-) Creating partition of a distributed table CREATE TABLE partitioning_test_2011 PARTITION OF partitioning_test FOR VALUES FROM ('2011-01-01') TO ('2012-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_2011 PARTITION OF partitionin... ^ -- new partition is automatically distributed as well SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2011') ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 6: logicalrelid IN ('partitioning_test', 'partitioning_test_20... ^ SELECT logicalrelid, count(*) FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2011') GROUP BY logicalrelid ORDER BY 1,2; ERROR: relation "partitioning_test" does not exist LINE 4: WHERE logicalrelid IN ('partitioning_test', 'partitioning_t... ^ -- 3-) Attaching non distributed table to a distributed table CREATE TABLE partitioning_test_2012(id int, time date); -- load some data INSERT INTO partitioning_test_2012 VALUES (5, '2012-06-06'); INSERT INTO partitioning_test_2012 VALUES (6, '2012-07-07'); ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2012 FOR VALUES FROM ('2012-01-01') TO ('2013-01-01'); ERROR: syntax error at or near "ATTACH" LINE 1: ALTER TABLE partitioning_test ATTACH PARTITION partitioning_... ^ -- attached partition is distributed as well SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2012') ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 6: logicalrelid IN ('partitioning_test', 'partitioning_test_20... ^ SELECT logicalrelid, count(*) FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2012') GROUP BY logicalrelid ORDER BY 1,2; ERROR: relation "partitioning_test" does not exist LINE 4: WHERE logicalrelid IN ('partitioning_test', 'partitioning_t... ^ -- try to insert a new data to hash partitioned table -- no partition is defined for value 5 INSERT INTO partitioning_hash_test VALUES (8, 5); ERROR: relation "partitioning_hash_test" does not exist LINE 1: INSERT INTO partitioning_hash_test VALUES (8, 5); ^ INSERT INTO partitioning_hash_test VALUES (9, 12); ERROR: relation "partitioning_hash_test" does not exist LINE 1: INSERT INTO partitioning_hash_test VALUES (9, 12); ^ CREATE TABLE partitioning_hash_test_2 (id int, subid int); INSERT INTO partitioning_hash_test_2 VALUES (8, 5); ALTER TABLE partitioning_hash_test ATTACH PARTITION partitioning_hash_test_2 FOR VALUES WITH (MODULUS 3, REMAINDER 2); ERROR: syntax error at or near "ATTACH" LINE 1: ALTER TABLE partitioning_hash_test ATTACH PARTITION partitio... ^ INSERT INTO partitioning_hash_test VALUES (9, 12); ERROR: relation "partitioning_hash_test" does not exist LINE 1: INSERT INTO partitioning_hash_test VALUES (9, 12); ^ -- see the data is loaded to shards SELECT * FROM partitioning_test ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test ORDER BY 1; ^ SELECT * FROM partitioning_hash_test ORDER BY 1; ERROR: relation "partitioning_hash_test" does not exist LINE 1: SELECT * FROM partitioning_hash_test ORDER BY 1; ^ -- 4-) Attaching distributed table to distributed table CREATE TABLE partitioning_test_2013(id int, time date); SELECT create_distributed_table('partitioning_test_2013', 'id'); create_distributed_table -------------------------- (1 row) -- load some data INSERT INTO partitioning_test_2013 VALUES (7, '2013-06-06'); INSERT INTO partitioning_test_2013 VALUES (8, '2013-07-07'); ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2013 FOR VALUES FROM ('2013-01-01') TO ('2014-01-01'); ERROR: syntax error at or near "ATTACH" LINE 1: ALTER TABLE partitioning_test ATTACH PARTITION partitioning_... ^ -- see the data is loaded to shards SELECT * FROM partitioning_test ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test ORDER BY 1; ^ -- 5-) Failure cases while creating distributed partitioned tables -- cannot distribute a partition if its parent is not distributed CREATE TABLE partitioning_test_failure(id int, time date) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: ...ABLE partitioning_test_failure(id int, time date) PARTITION ... ^ CREATE TABLE partitioning_test_failure_2009 PARTITION OF partitioning_test_failure FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_failure_2009 PARTITION OF par... ^ SELECT create_distributed_table('partitioning_test_failure_2009', 'id'); ERROR: relation "partitioning_test_failure_2009" does not exist LINE 1: SELECT create_distributed_table('partitioning_test_failure_2... ^ -- only hash distributed tables can have partitions SELECT create_distributed_table('partitioning_test_failure', 'id', 'append'); ERROR: relation "partitioning_test_failure" does not exist LINE 1: SELECT create_distributed_table('partitioning_test_failure',... ^ SELECT create_distributed_table('partitioning_test_failure', 'id', 'range'); ERROR: relation "partitioning_test_failure" does not exist LINE 1: SELECT create_distributed_table('partitioning_test_failure',... ^ SELECT create_reference_table('partitioning_test_failure'); ERROR: relation "partitioning_test_failure" does not exist LINE 1: SELECT create_reference_table('partitioning_test_failure'); ^ SET citus.shard_replication_factor TO 1; -- non-distributed tables cannot have distributed partitions; DROP TABLE partitioning_test_failure_2009; ERROR: table "partitioning_test_failure_2009" does not exist CREATE TABLE partitioning_test_failure_2009(id int, time date); SELECT create_distributed_table('partitioning_test_failure_2009', 'id'); create_distributed_table -------------------------- (1 row) ALTER TABLE partitioning_test_failure ATTACH PARTITION partitioning_test_failure_2009 FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "ATTACH" LINE 1: ALTER TABLE partitioning_test_failure ATTACH PARTITION parti... ^ -- multi-level partitioning is not allowed DROP TABLE partitioning_test_failure_2009; CREATE TABLE partitioning_test_failure_2009 PARTITION OF partitioning_test_failure FOR VALUES FROM ('2009-01-01') TO ('2010-01-01') PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_failure_2009 PARTITION OF par... ^ SELECT create_distributed_table('partitioning_test_failure', 'id'); ERROR: relation "partitioning_test_failure" does not exist LINE 1: SELECT create_distributed_table('partitioning_test_failure',... ^ -- multi-level partitioning is not allowed in different order DROP TABLE partitioning_test_failure_2009; ERROR: table "partitioning_test_failure_2009" does not exist SELECT create_distributed_table('partitioning_test_failure', 'id'); ERROR: relation "partitioning_test_failure" does not exist LINE 1: SELECT create_distributed_table('partitioning_test_failure',... ^ CREATE TABLE partitioning_test_failure_2009 PARTITION OF partitioning_test_failure FOR VALUES FROM ('2009-01-01') TO ('2010-01-01') PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_failure_2009 PARTITION OF par... ^ -- -- DMLs in distributed partitioned tables -- -- test COPY -- COPY data to partitioned table COPY partitioning_test FROM STDIN WITH CSV; ERROR: relation "partitioning_test" does not exist 9,2009-01-01 10,2010-01-01 11,2011-01-01 12,2012-01-01 \. invalid command \. -- COPY data to partition directly COPY partitioning_test_2009 FROM STDIN WITH CSV; ERROR: syntax error at or near "9" LINE 1: 9,2009-01-01 ^ 13,2009-01-02 14,2009-01-03 \. invalid command \. -- see the data is loaded to shards SELECT * FROM partitioning_test WHERE id >= 9 ORDER BY 1; ERROR: syntax error at or near "13" LINE 1: 13,2009-01-02 ^ -- test INSERT -- INSERT INTO the partitioned table INSERT INTO partitioning_test VALUES(15, '2009-02-01'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(15, '2009-02-01'); ^ INSERT INTO partitioning_test VALUES(16, '2010-02-01'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(16, '2010-02-01'); ^ INSERT INTO partitioning_test VALUES(17, '2011-02-01'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(17, '2011-02-01'); ^ INSERT INTO partitioning_test VALUES(18, '2012-02-01'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(18, '2012-02-01'); ^ -- INSERT INTO the partitions directly table INSERT INTO partitioning_test VALUES(19, '2009-02-02'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(19, '2009-02-02'); ^ INSERT INTO partitioning_test VALUES(20, '2010-02-02'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(20, '2010-02-02'); ^ -- see the data is loaded to shards SELECT * FROM partitioning_test WHERE id >= 15 ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id >= 15 ORDER BY 1; ^ -- test INSERT/SELECT -- INSERT/SELECT from partition to partitioned table INSERT INTO partitioning_test SELECT * FROM partitioning_test_2011; ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test SELECT * FROM partitioning_tes... ^ -- INSERT/SELECT from partitioned table to partition INSERT INTO partitioning_test_2012 SELECT * FROM partitioning_test WHERE time >= '2012-01-01' AND time < '2013-01-01'; ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test_2012 SELECT * FROM partitionin... ^ -- see the data is loaded to shards (rows in the given range should be duplicated) SELECT * FROM partitioning_test WHERE time >= '2011-01-01' AND time < '2013-01-01' ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE time >= '2011-01-01' A... ^ -- test UPDATE -- UPDATE partitioned table UPDATE partitioning_test SET time = '2013-07-07' WHERE id = 7; ERROR: relation "partitioning_test" does not exist LINE 1: UPDATE partitioning_test SET time = '2013-07-07' WHERE id = ... ^ -- UPDATE partition directly UPDATE partitioning_test_2013 SET time = '2013-08-08' WHERE id = 8; -- see the data is updated SELECT * FROM partitioning_test WHERE id = 7 OR id = 8 ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id = 7 OR id = 8 ORDER... ^ -- UPDATE that tries to move a row to a non-existing partition (this should fail) UPDATE partitioning_test SET time = '2020-07-07' WHERE id = 7; ERROR: relation "partitioning_test" does not exist LINE 1: UPDATE partitioning_test SET time = '2020-07-07' WHERE id = ... ^ -- UPDATE with subqueries on partitioned table UPDATE partitioning_test SET time = time + INTERVAL '1 day' WHERE id IN (SELECT id FROM partitioning_test WHERE id = 1); ERROR: relation "partitioning_test" does not exist LINE 2: partitioning_test ^ -- UPDATE with subqueries on partition UPDATE partitioning_test_2009 SET time = time + INTERVAL '1 month' WHERE id IN (SELECT id FROM partitioning_test WHERE id = 2); ERROR: relation "partitioning_test_2009" does not exist LINE 2: partitioning_test_2009 ^ -- see the data is updated SELECT * FROM partitioning_test WHERE id = 1 OR id = 2 ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id = 1 OR id = 2 ORDER... ^ -- test DELETE -- DELETE from partitioned table DELETE FROM partitioning_test WHERE id = 9; ERROR: relation "partitioning_test" does not exist LINE 1: DELETE FROM partitioning_test WHERE id = 9; ^ -- DELETE from partition directly DELETE FROM partitioning_test_2010 WHERE id = 10; ERROR: relation "partitioning_test_2010" does not exist LINE 1: DELETE FROM partitioning_test_2010 WHERE id = 10; ^ -- see the data is deleted SELECT * FROM partitioning_test WHERE id = 9 OR id = 10 ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id = 9 OR id = 10 ORDE... ^ -- create default partition CREATE TABLE partitioning_test_default PARTITION OF partitioning_test DEFAULT; ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_default PARTITION OF partitio... ^ \d+ partitioning_test INSERT INTO partitioning_test VALUES(21, '2014-02-02'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(21, '2014-02-02'); ^ INSERT INTO partitioning_test VALUES(22, '2015-04-02'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(22, '2015-04-02'); ^ -- see they are inserted into default partition SELECT * FROM partitioning_test WHERE id > 20; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id > 20; ^ SELECT * FROM partitioning_test_default; ERROR: relation "partitioning_test_default" does not exist LINE 1: SELECT * FROM partitioning_test_default; ^ -- create a new partition (will fail) CREATE TABLE partitioning_test_2014 PARTITION OF partitioning_test FOR VALUES FROM ('2014-01-01') TO ('2015-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_2014 PARTITION OF partitionin... ^ BEGIN; ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_default; ERROR: syntax error at or near "DETACH" LINE 1: ALTER TABLE partitioning_test DETACH PARTITION partitioning_... ^ CREATE TABLE partitioning_test_2014 PARTITION OF partitioning_test FOR VALUES FROM ('2014-01-01') TO ('2015-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_2014 PARTITION OF partitionin... ^ INSERT INTO partitioning_test SELECT * FROM partitioning_test_default WHERE time >= '2014-01-01' AND time < '2015-01-01'; ERROR: current transaction is aborted, commands ignored until end of transaction block DELETE FROM partitioning_test_default WHERE time >= '2014-01-01' AND time < '2015-01-01'; ERROR: current transaction is aborted, commands ignored until end of transaction block ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_default DEFAULT; ERROR: syntax error at or near "ATTACH" LINE 1: ALTER TABLE partitioning_test ATTACH PARTITION partitioning_... ^ END; -- see data is in the table, but some moved out from default partition SELECT * FROM partitioning_test WHERE id > 20; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id > 20; ^ SELECT * FROM partitioning_test_default; ERROR: relation "partitioning_test_default" does not exist LINE 1: SELECT * FROM partitioning_test_default; ^ -- test master_modify_multiple_shards -- master_modify_multiple_shards on partitioned table SELECT master_modify_multiple_shards('UPDATE partitioning_test SET time = time + INTERVAL ''1 day'''); ERROR: relation "partitioning_test" does not exist -- see rows are UPDATED SELECT * FROM partitioning_test ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test ORDER BY 1; ^ -- master_modify_multiple_shards on partition directly SELECT master_modify_multiple_shards('UPDATE partitioning_test_2009 SET time = time + INTERVAL ''1 day'''); ERROR: relation "partitioning_test_2009" does not exist -- see rows are UPDATED SELECT * FROM partitioning_test_2009 ORDER BY 1; ERROR: relation "partitioning_test_2009" does not exist LINE 1: SELECT * FROM partitioning_test_2009 ORDER BY 1; ^ -- test master_modify_multiple_shards which fails in workers (updated value is outside of partition bounds) SELECT master_modify_multiple_shards('UPDATE partitioning_test_2009 SET time = time + INTERVAL ''6 month'''); ERROR: relation "partitioning_test_2009" does not exist -- -- DDL in distributed partitioned tables -- -- test CREATE INDEX -- CREATE INDEX on partitioned table - this will error out -- on earlier versions of postgres earlier than 11. CREATE INDEX partitioning_index ON partitioning_test(id); ERROR: relation "partitioning_test" does not exist -- CREATE INDEX on partition CREATE INDEX partitioning_2009_index ON partitioning_test_2009(id); ERROR: relation "partitioning_test_2009" does not exist -- CREATE INDEX CONCURRENTLY on partition CREATE INDEX CONCURRENTLY partitioned_2010_index ON partitioning_test_2010(id); ERROR: relation "partitioning_test_2010" does not exist -- see index is created SELECT tablename, indexname FROM pg_indexes WHERE tablename LIKE 'partitioning_test%' ORDER BY indexname; tablename | indexname -----------+----------- (0 rows) -- test drop -- indexes created on parent table can only be dropped on parent table -- ie using the same index name -- following will fail DROP INDEX partitioning_test_2009_id_idx; ERROR: index "partitioning_test_2009_id_idx" does not exist -- but dropping index on parent table will succeed DROP INDEX partitioning_index; ERROR: index "partitioning_index" does not exist -- this index was already created on partition table DROP INDEX partitioning_2009_index; ERROR: index "partitioning_2009_index" does not exist -- test drop index on non-distributed, partitioned table CREATE TABLE non_distributed_partitioned_table(a int, b int) PARTITION BY RANGE (a); ERROR: syntax error at or near "PARTITION" LINE 1: ...E non_distributed_partitioned_table(a int, b int) PARTITION ... ^ CREATE TABLE non_distributed_partitioned_table_1 PARTITION OF non_distributed_partitioned_table FOR VALUES FROM (0) TO (10); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE non_distributed_partitioned_table_1 PARTITION O... ^ CREATE INDEX non_distributed_partitioned_table_index ON non_distributed_partitioned_table(a); ERROR: relation "non_distributed_partitioned_table" does not exist -- see index is created SELECT tablename, indexname FROM pg_indexes WHERE tablename LIKE 'non_distributed%' ORDER BY indexname; tablename | indexname -----------+----------- (0 rows) -- drop the index and see it is dropped DROP INDEX non_distributed_partitioned_table_index; ERROR: index "non_distributed_partitioned_table_index" does not exist SELECT tablename, indexname FROM pg_indexes WHERE tablename LIKE 'non_distributed%' ORDER BY indexname; tablename | indexname -----------+----------- (0 rows) -- test add COLUMN -- add COLUMN to partitioned table ALTER TABLE partitioning_test ADD new_column int; ERROR: relation "partitioning_test" does not exist -- add COLUMN to partition - this will error out ALTER TABLE partitioning_test_2010 ADD new_column_2 int; ERROR: relation "partitioning_test_2010" does not exist -- see additional column is created SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test'::regclass ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT name, type FROM table_attrs WHERE relid = 'partitioni... ^ SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test_2010'::regclass ORDER BY 1; ERROR: relation "partitioning_test_2010" does not exist LINE 1: SELECT name, type FROM table_attrs WHERE relid = 'partitioni... ^ -- test add PRIMARY KEY -- add PRIMARY KEY to partitioned table - this will error out ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_primary PRIMARY KEY (id); ERROR: relation "partitioning_test" does not exist -- ADD PRIMARY KEY to partition ALTER TABLE partitioning_test_2009 ADD CONSTRAINT partitioning_2009_primary PRIMARY KEY (id); ERROR: relation "partitioning_test_2009" does not exist -- see PRIMARY KEY is created SELECT table_name, constraint_name, constraint_type FROM information_schema.table_constraints WHERE table_name = 'partitioning_test_2009' AND constraint_name = 'partitioning_2009_primary'; table_name | constraint_name | constraint_type ------------+-----------------+----------------- (0 rows) -- however, you can add primary key if it contains both distribution and partition key ALTER TABLE partitioning_hash_test ADD CONSTRAINT partitioning_hash_primary PRIMARY KEY (id, subid); ERROR: relation "partitioning_hash_test" does not exist -- see PRIMARY KEY is created SELECT table_name, constraint_name, constraint_type FROM information_schema.table_constraints WHERE table_name LIKE 'partitioning_hash_test%' AND constraint_type = 'PRIMARY KEY' ORDER BY 1; table_name | constraint_name | constraint_type ------------+-----------------+----------------- (0 rows) -- test ADD FOREIGN CONSTRAINT -- add FOREIGN CONSTRAINT to partitioned table -- this will error out (it is a self reference) ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_foreign FOREIGN KEY (id) REFERENCES partitioning_test_2009 (id); ERROR: relation "partitioning_test" does not exist -- add FOREIGN CONSTRAINT to partition INSERT INTO partitioning_test_2009 VALUES (5, '2009-06-06'); ERROR: relation "partitioning_test_2009" does not exist LINE 1: INSERT INTO partitioning_test_2009 VALUES (5, '2009-06-06'); ^ INSERT INTO partitioning_test_2009 VALUES (6, '2009-07-07'); ERROR: relation "partitioning_test_2009" does not exist LINE 1: INSERT INTO partitioning_test_2009 VALUES (6, '2009-07-07'); ^ INSERT INTO partitioning_test_2009 VALUES(12, '2009-02-01'); ERROR: relation "partitioning_test_2009" does not exist LINE 1: INSERT INTO partitioning_test_2009 VALUES(12, '2009-02-01'); ^ INSERT INTO partitioning_test_2009 VALUES(18, '2009-02-01'); ERROR: relation "partitioning_test_2009" does not exist LINE 1: INSERT INTO partitioning_test_2009 VALUES(18, '2009-02-01'); ^ ALTER TABLE partitioning_test_2012 ADD CONSTRAINT partitioning_2012_foreign FOREIGN KEY (id) REFERENCES partitioning_test_2009 (id) ON DELETE CASCADE; ERROR: relation "partitioning_test_2009" does not exist -- see FOREIGN KEY is created SELECT "Constraint" FROM table_fkeys WHERE relid = 'partitioning_test_2012'::regclass ORDER BY 1; Constraint ------------ (0 rows) -- test ON DELETE CASCADE works DELETE FROM partitioning_test_2009 WHERE id = 5; ERROR: relation "partitioning_test_2009" does not exist LINE 1: DELETE FROM partitioning_test_2009 WHERE id = 5; ^ -- see that element is deleted from both partitions SELECT * FROM partitioning_test_2009 WHERE id = 5 ORDER BY 1; ERROR: relation "partitioning_test_2009" does not exist LINE 1: SELECT * FROM partitioning_test_2009 WHERE id = 5 ORDER BY 1... ^ SELECT * FROM partitioning_test_2012 WHERE id = 5 ORDER BY 1; id | time ----+------------ 5 | 06-06-2012 (1 row) -- test DETACH partition ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2009; ERROR: syntax error at or near "DETACH" LINE 1: ALTER TABLE partitioning_test DETACH PARTITION partitioning_... ^ -- see DETACHed partitions content is not accessible from partitioning_test; SELECT * FROM partitioning_test WHERE time >= '2009-01-01' AND time < '2010-01-01' ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE time >= '2009-01-01' A... ^ -- delete from default partition DELETE FROM partitioning_test WHERE time >= '2015-01-01'; ERROR: relation "partitioning_test" does not exist LINE 1: DELETE FROM partitioning_test WHERE time >= '2015-01-01'; ^ SELECT * FROM partitioning_test_default; ERROR: relation "partitioning_test_default" does not exist LINE 1: SELECT * FROM partitioning_test_default; ^ -- create a reference table for foreign key test CREATE TABLE partitioning_test_reference(id int PRIMARY KEY, subid int); INSERT INTO partitioning_test_reference SELECT a, a FROM generate_series(1, 50) a; SELECT create_reference_table('partitioning_test_reference'); NOTICE: Copying data from local table... create_reference_table ------------------------ (1 row) ALTER TABLE partitioning_test ADD CONSTRAINT partitioning_reference_fkey FOREIGN KEY (id) REFERENCES partitioning_test_reference(id) ON DELETE CASCADE; ERROR: relation "partitioning_test" does not exist CREATE TABLE partitioning_test_foreign_key(id int PRIMARY KEY, value int); SELECT create_distributed_table('partitioning_test_foreign_key', 'id'); create_distributed_table -------------------------- (1 row) INSERT INTO partitioning_test_foreign_key SELECT * FROM partitioning_test_reference; ALTER TABLE partitioning_hash_test ADD CONSTRAINT partitioning_reference_fk_test FOREIGN KEY (id) REFERENCES partitioning_test_foreign_key(id) ON DELETE CASCADE; ERROR: relation "partitioning_hash_test" does not exist -- check foreign keys on partitions SELECT table_name, constraint_name, constraint_type FROm information_schema.table_constraints WHERE table_name LIKE 'partitioning_hash_test%' AND constraint_type = 'FOREIGN KEY' ORDER BY 1,2; table_name | constraint_name | constraint_type ------------+-----------------+----------------- (0 rows) -- check foreign keys on partition shards -- there is some text ordering issue regarding table name -- forcing integer sort by extracting shardid CREATE TYPE foreign_key_details AS (table_name text, constraint_name text, constraint_type text); SELECT right(table_name, 7)::int as shardid, * FROM ( SELECT (json_populate_record(NULL::foreign_key_details, json_array_elements_text(result::json)::json )).* FROM run_command_on_workers($$ SELECT COALESCE(json_agg(row_to_json(q)), '[]'::json) FROM ( SELECT table_name, constraint_name, constraint_type FROM information_schema.table_constraints WHERE table_name LIKE 'partitioning_hash_test%' AND constraint_type = 'FOREIGN KEY' ORDER BY 1, 2, 3 ) q $$) ) w ORDER BY 1, 2, 3, 4; shardid | table_name | constraint_name | constraint_type ---------+------------+-----------------+----------------- (0 rows) DROP TYPE foreign_key_details; -- set replication factor back to 1 since it gots reset -- after connection re-establishment SET citus.shard_replication_factor TO 1; SELECT * FROM partitioning_test WHERE id = 11 or id = 12; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id = 11 or id = 12; ^ DELETE FROM partitioning_test_reference WHERE id = 11 or id = 12; SELECT * FROM partitioning_hash_test ORDER BY 1, 2; ERROR: relation "partitioning_hash_test" does not exist LINE 1: SELECT * FROM partitioning_hash_test ORDER BY 1, 2; ^ DELETE FROM partitioning_test_foreign_key WHERE id = 2 OR id = 9; -- see data is deleted from referencing table SELECT * FROM partitioning_test WHERE id = 11 or id = 12; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id = 11 or id = 12; ^ SELECT * FROM partitioning_hash_test ORDER BY 1, 2; ERROR: relation "partitioning_hash_test" does not exist LINE 1: SELECT * FROM partitioning_hash_test ORDER BY 1, 2; ^ -- -- Transaction tests -- -- DDL in transaction BEGIN; ALTER TABLE partitioning_test ADD newer_column int; ERROR: relation "partitioning_test" does not exist -- see additional column is created SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test'::regclass ORDER BY 1; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- see rollback is successful SELECT name, type FROM table_attrs WHERE relid = 'partitioning_test'::regclass ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT name, type FROM table_attrs WHERE relid = 'partitioni... ^ -- COPY in transaction BEGIN; COPY partitioning_test FROM STDIN WITH CSV; ERROR: relation "partitioning_test" does not exist 22,2010-01-01,22 23,2011-01-01,23 24,2013-01-01,24 \. invalid command \. -- see the data is loaded to shards SELECT * FROM partitioning_test WHERE id = 22 ORDER BY 1; ERROR: syntax error at or near "22" LINE 1: 22,2010-01-01,22 ^ SELECT * FROM partitioning_test WHERE id = 23 ORDER BY 1; ERROR: current transaction is aborted, commands ignored until end of transaction block SELECT * FROM partitioning_test WHERE id = 24 ORDER BY 1; ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- see rollback is successful SELECT * FROM partitioning_test WHERE id >= 22 ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id >= 22 ORDER BY 1; ^ -- DML in transaction BEGIN; -- INSERT in transaction INSERT INTO partitioning_test VALUES(25, '2010-02-02'); ERROR: relation "partitioning_test" does not exist LINE 1: INSERT INTO partitioning_test VALUES(25, '2010-02-02'); ^ -- see the data is loaded to shards SELECT * FROM partitioning_test WHERE id = 25 ORDER BY 1; ERROR: current transaction is aborted, commands ignored until end of transaction block -- INSERT/SELECT in transaction INSERT INTO partitioning_test SELECT * FROM partitioning_test WHERE id = 25; ERROR: current transaction is aborted, commands ignored until end of transaction block -- see the data is loaded to shards SELECT * FROM partitioning_test WHERE id = 25 ORDER BY 1; ERROR: current transaction is aborted, commands ignored until end of transaction block -- UPDATE in transaction UPDATE partitioning_test SET time = '2010-10-10' WHERE id = 25; ERROR: current transaction is aborted, commands ignored until end of transaction block -- see the data is updated SELECT * FROM partitioning_test WHERE id = 25 ORDER BY 1; ERROR: current transaction is aborted, commands ignored until end of transaction block -- perform operations on partition and partioned tables together INSERT INTO partitioning_test VALUES(26, '2010-02-02', 26); ERROR: current transaction is aborted, commands ignored until end of transaction block INSERT INTO partitioning_test_2010 VALUES(26, '2010-02-02', 26); ERROR: current transaction is aborted, commands ignored until end of transaction block COPY partitioning_test FROM STDIN WITH CSV; ERROR: current transaction is aborted, commands ignored until end of transaction block 26,2010-02-02,26 \. invalid command \. COPY partitioning_test_2010 FROM STDIN WITH CSV; ERROR: syntax error at or near "26" LINE 1: 26,2010-02-02,26 ^ 26,2010-02-02,26 \. invalid command \. -- see the data is loaded to shards (we should see 4 rows with same content) SELECT * FROM partitioning_test WHERE id = 26 ORDER BY 1; ERROR: syntax error at or near "26" LINE 1: 26,2010-02-02,26 ^ ROLLBACK; -- see rollback is successful SELECT * FROM partitioning_test WHERE id = 26 ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE id = 26 ORDER BY 1; ^ -- DETACH and DROP in a transaction BEGIN; ALTER TABLE partitioning_test DETACH PARTITION partitioning_test_2011; ERROR: syntax error at or near "DETACH" LINE 1: ALTER TABLE partitioning_test DETACH PARTITION partitioning_... ^ DROP TABLE partitioning_test_2011; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- see DROPed partitions content is not accessible SELECT * FROM partitioning_test WHERE time >= '2011-01-01' AND time < '2012-01-01' ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE time >= '2011-01-01' A... ^ -- -- Misc tests -- -- test TRUNCATE -- test TRUNCATE partition TRUNCATE partitioning_test_2012; -- see partition is TRUNCATEd SELECT * FROM partitioning_test_2012 ORDER BY 1; id | time ----+------ (0 rows) -- test TRUNCATE partitioned table TRUNCATE partitioning_test; ERROR: relation "partitioning_test" does not exist -- see partitioned table is TRUNCATEd SELECT * FROM partitioning_test ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test ORDER BY 1; ^ -- test DROP -- test DROP partition INSERT INTO partitioning_test_2010 VALUES(27, '2010-02-01'); ERROR: relation "partitioning_test_2010" does not exist LINE 1: INSERT INTO partitioning_test_2010 VALUES(27, '2010-02-01'); ^ DROP TABLE partitioning_test_2010; ERROR: table "partitioning_test_2010" does not exist -- see DROPped partitions content is not accessible from partitioning_test; SELECT * FROM partitioning_test WHERE time >= '2010-01-01' AND time < '2011-01-01' ORDER BY 1; ERROR: relation "partitioning_test" does not exist LINE 1: SELECT * FROM partitioning_test WHERE time >= '2010-01-01' A... ^ -- test DROP partitioned table DROP TABLE partitioning_test; ERROR: table "partitioning_test" does not exist DROP TABLE partitioning_test_reference; -- dropping the parent should CASCADE to the children as well SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'partitioning_test%' ORDER BY 1; table_name ------------------------------- partitioning_test_2012 partitioning_test_2013 partitioning_test_foreign_key (3 rows) -- test distributing partitioned table colocated with non-partitioned table CREATE TABLE partitioned_users_table (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: ... int, value_2 int, value_3 float, value_4 bigint) PARTITION ... ^ CREATE TABLE partitioned_events_table (user_id int, time timestamp, event_type int, value_2 int, value_3 float, value_4 bigint) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: ... int, value_2 int, value_3 float, value_4 bigint) PARTITION ... ^ SELECT create_distributed_table('partitioned_users_table', 'user_id', colocate_with => 'users_table'); ERROR: relation "partitioned_users_table" does not exist LINE 1: SELECT create_distributed_table('partitioned_users_table', '... ^ SELECT create_distributed_table('partitioned_events_table', 'user_id', colocate_with => 'events_table'); ERROR: relation "partitioned_events_table" does not exist LINE 1: SELECT create_distributed_table('partitioned_events_table', ... ^ -- INSERT/SELECT from regular table to partitioned table CREATE TABLE partitioned_users_table_2009 PARTITION OF partitioned_users_table FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioned_users_table_2009 PARTITION OF parti... ^ CREATE TABLE partitioned_events_table_2009 PARTITION OF partitioned_events_table FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioned_events_table_2009 PARTITION OF part... ^ INSERT INTO partitioned_events_table SELECT * FROM events_table; ERROR: relation "partitioned_events_table" does not exist LINE 1: INSERT INTO partitioned_events_table SELECT * FROM events_ta... ^ INSERT INTO partitioned_users_table_2009 SELECT * FROM users_table; ERROR: relation "partitioned_users_table_2009" does not exist LINE 1: INSERT INTO partitioned_users_table_2009 SELECT * FROM users... ^ -- -- Complex JOINs, subqueries, UNIONs etc... -- -- subquery with UNIONs on partitioned table SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM (SELECT *, random() FROM (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM (SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM( (SELECT "events"."user_id", "events"."time", 0 AS event FROM partitioned_events_table as "events" WHERE event_type IN (1, 2) ) UNION (SELECT "events"."user_id", "events"."time", 1 AS event FROM partitioned_events_table as "events" WHERE event_type IN (3, 4) ) UNION (SELECT "events"."user_id", "events"."time", 2 AS event FROM partitioned_events_table as "events" WHERE event_type IN (5, 6) ) UNION (SELECT "events"."user_id", "events"."time", 3 AS event FROM partitioned_events_table as "events" WHERE event_type IN (1, 6))) t1 GROUP BY "t1"."user_id") AS t) "q" ) AS final_query GROUP BY types ORDER BY types; ERROR: relation "partitioned_events_table" does not exist LINE 14: partitioned_events_table as "events" ^ -- UNION and JOIN on both partitioned and regular tables SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM (SELECT *, random() FROM (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM (SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( (SELECT * FROM (SELECT "events"."time", 0 AS event, "events"."user_id" FROM partitioned_events_table as "events" WHERE event_type IN (1, 2)) events_subquery_1) UNION (SELECT * FROM ( SELECT * FROM ( SELECT max("events"."time"), 0 AS event, "events"."user_id" FROM events_table as "events", users_table as "users" WHERE events.user_id = users.user_id AND event_type IN (1, 2) GROUP BY "events"."user_id" ) as events_subquery_5 ) events_subquery_2) UNION (SELECT * FROM (SELECT "events"."time", 2 AS event, "events"."user_id" FROM partitioned_events_table as "events" WHERE event_type IN (3, 4)) events_subquery_3) UNION (SELECT * FROM (SELECT "events"."time", 3 AS event, "events"."user_id" FROM events_table as "events" WHERE event_type IN (5, 6)) events_subquery_4) ) t1 GROUP BY "t1"."user_id") AS t) "q" INNER JOIN (SELECT "users"."user_id" FROM partitioned_users_table as "users" WHERE value_1 > 2 and value_1 < 5) AS t ON (t.user_id = q.user_id)) as final_query GROUP BY types ORDER BY types; ERROR: relation "partitioned_events_table" does not exist LINE 18: partitioned_events_table as "events" ^ -- test LIST partitioning CREATE TABLE list_partitioned_events_table (user_id int, time date, event_type int, value_2 int, value_3 float, value_4 bigint) PARTITION BY LIST (time); ERROR: syntax error at or near "PARTITION" LINE 1: ... int, value_2 int, value_3 float, value_4 bigint) PARTITION ... ^ CREATE TABLE list_partitioned_events_table_2014_01_01_05 PARTITION OF list_partitioned_events_table FOR VALUES IN ('2017-11-21', '2017-11-22', '2017-11-23', '2017-11-24', '2017-11-25'); ERROR: syntax error at or near "PARTITION" LINE 1: ...TABLE list_partitioned_events_table_2014_01_01_05 PARTITION ... ^ CREATE TABLE list_partitioned_events_table_2014_01_06_10 PARTITION OF list_partitioned_events_table FOR VALUES IN ('2017-11-26', '2017-11-27', '2017-11-28', '2017-11-29', '2017-11-30'); ERROR: syntax error at or near "PARTITION" LINE 1: ...TABLE list_partitioned_events_table_2014_01_06_10 PARTITION ... ^ CREATE TABLE list_partitioned_events_table_2014_01_11_15 PARTITION OF list_partitioned_events_table FOR VALUES IN ('2017-12-01', '2017-12-02', '2017-12-03', '2017-12-04', '2017-12-05'); ERROR: syntax error at or near "PARTITION" LINE 1: ...TABLE list_partitioned_events_table_2014_01_11_15 PARTITION ... ^ -- test distributing partitioned table colocated with another partitioned table SELECT create_distributed_table('list_partitioned_events_table', 'user_id', colocate_with => 'partitioned_events_table'); ERROR: relation "list_partitioned_events_table" does not exist LINE 1: SELECT create_distributed_table('list_partitioned_events_tab... ^ -- INSERT/SELECT from partitioned table to partitioned table INSERT INTO list_partitioned_events_table SELECT user_id, date_trunc('day', time) as time, event_type, value_2, value_3, value_4 FROM events_table WHERE time >= '2017-11-21' AND time <= '2017-12-01'; ERROR: relation "list_partitioned_events_table" does not exist LINE 2: list_partitioned_events_table ^ -- LEFT JOINs used with INNER JOINs on range partitioned table, list partitioned table and non-partitioned table SELECT count(*) AS cnt, "generated_group_field" FROM (SELECT "eventQuery"."user_id", random(), generated_group_field FROM (SELECT "multi_group_wrapper_1".*, generated_group_field, random() FROM (SELECT * FROM (SELECT "list_partitioned_events_table"."time", "list_partitioned_events_table"."user_id" as event_user_id FROM list_partitioned_events_table as "list_partitioned_events_table" WHERE user_id > 2) "temp_data_queries" INNER JOIN (SELECT "users"."user_id" FROM partitioned_users_table as "users" WHERE user_id > 2 and value_2 = 1) "user_filters_1" ON ("temp_data_queries".event_user_id = "user_filters_1".user_id)) AS "multi_group_wrapper_1" LEFT JOIN (SELECT "users"."user_id" AS "user_id", value_2 AS "generated_group_field" FROM partitioned_users_table as "users") "left_group_by_1" ON ("left_group_by_1".user_id = "multi_group_wrapper_1".event_user_id)) "eventQuery") "pushedDownQuery" GROUP BY "generated_group_field" ORDER BY cnt DESC, generated_group_field ASC LIMIT 10; ERROR: relation "list_partitioned_events_table" does not exist LINE 15: list_partitioned_events_table as "list_partitio... ^ -- -- Additional partitioning features -- -- test multi column partitioning CREATE TABLE multi_column_partitioning(c1 int, c2 int) PARTITION BY RANGE (c1, c2); ERROR: syntax error at or near "PARTITION" LINE 1: ...E TABLE multi_column_partitioning(c1 int, c2 int) PARTITION ... ^ CREATE TABLE multi_column_partitioning_0_0_10_0 PARTITION OF multi_column_partitioning FOR VALUES FROM (0, 0) TO (10, 0); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE multi_column_partitioning_0_0_10_0 PARTITION OF... ^ SELECT create_distributed_table('multi_column_partitioning', 'c1'); ERROR: relation "multi_column_partitioning" does not exist LINE 1: SELECT create_distributed_table('multi_column_partitioning',... ^ -- test INSERT to multi-column partitioned table INSERT INTO multi_column_partitioning VALUES(1, 1); ERROR: relation "multi_column_partitioning" does not exist LINE 1: INSERT INTO multi_column_partitioning VALUES(1, 1); ^ INSERT INTO multi_column_partitioning_0_0_10_0 VALUES(5, -5); ERROR: relation "multi_column_partitioning_0_0_10_0" does not exist LINE 1: INSERT INTO multi_column_partitioning_0_0_10_0 VALUES(5, -5)... ^ -- test INSERT to multi-column partitioned table where no suitable partition exists INSERT INTO multi_column_partitioning VALUES(10, 1); ERROR: relation "multi_column_partitioning" does not exist LINE 1: INSERT INTO multi_column_partitioning VALUES(10, 1); ^ -- test with MINVALUE/MAXVALUE CREATE TABLE multi_column_partitioning_10_max_20_min PARTITION OF multi_column_partitioning FOR VALUES FROM (10, MAXVALUE) TO (20, MINVALUE); ERROR: syntax error at or near "PARTITION" LINE 1: ...ATE TABLE multi_column_partitioning_10_max_20_min PARTITION ... ^ -- test INSERT to partition with MINVALUE/MAXVALUE bounds INSERT INTO multi_column_partitioning VALUES(11, -11); ERROR: relation "multi_column_partitioning" does not exist LINE 1: INSERT INTO multi_column_partitioning VALUES(11, -11); ^ INSERT INTO multi_column_partitioning_10_max_20_min VALUES(19, -19); ERROR: relation "multi_column_partitioning_10_max_20_min" does not exist LINE 1: INSERT INTO multi_column_partitioning_10_max_20_min VALUES(1... ^ -- test INSERT to multi-column partitioned table where no suitable partition exists INSERT INTO multi_column_partitioning VALUES(20, -20); ERROR: relation "multi_column_partitioning" does not exist LINE 1: INSERT INTO multi_column_partitioning VALUES(20, -20); ^ -- see data is loaded to multi-column partitioned table SELECT * FROM multi_column_partitioning ORDER BY 1, 2; ERROR: relation "multi_column_partitioning" does not exist LINE 1: SELECT * FROM multi_column_partitioning ORDER BY 1, 2; ^ -- -- Tests for locks on partitioned tables -- CREATE TABLE partitioning_locks(id int, ref_id int, time date) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: ...partitioning_locks(id int, ref_id int, time date) PARTITION ... ^ -- create its partitions CREATE TABLE partitioning_locks_2009 PARTITION OF partitioning_locks FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_locks_2009 PARTITION OF partitioni... ^ CREATE TABLE partitioning_locks_2010 PARTITION OF partitioning_locks FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_locks_2010 PARTITION OF partitioni... ^ -- distribute partitioned table SELECT create_distributed_table('partitioning_locks', 'id'); ERROR: relation "partitioning_locks" does not exist LINE 1: SELECT create_distributed_table('partitioning_locks', 'id'); ^ -- test locks on router SELECT BEGIN; SELECT * FROM partitioning_locks WHERE id = 1 ORDER BY 1, 2; ERROR: relation "partitioning_locks" does not exist LINE 1: SELECT * FROM partitioning_locks WHERE id = 1 ORDER BY 1, 2; ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on real-time SELECT BEGIN; SELECT * FROM partitioning_locks ORDER BY 1, 2; ERROR: relation "partitioning_locks" does not exist LINE 1: SELECT * FROM partitioning_locks ORDER BY 1, 2; ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on task-tracker SELECT SET citus.task_executor_type TO 'task-tracker'; BEGIN; SELECT * FROM partitioning_locks AS pl1 JOIN partitioning_locks AS pl2 ON pl1.id = pl2.ref_id ORDER BY 1, 2; ERROR: relation "partitioning_locks" does not exist LINE 1: SELECT * FROM partitioning_locks AS pl1 JOIN partitioning_lo... ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; SET citus.task_executor_type TO 'real-time'; -- test locks on INSERT BEGIN; INSERT INTO partitioning_locks VALUES(1, 1, '2009-01-01'); ERROR: relation "partitioning_locks" does not exist LINE 1: INSERT INTO partitioning_locks VALUES(1, 1, '2009-01-01'); ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on UPDATE BEGIN; UPDATE partitioning_locks SET time = '2009-02-01' WHERE id = 1; ERROR: relation "partitioning_locks" does not exist LINE 1: UPDATE partitioning_locks SET time = '2009-02-01' WHERE id =... ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on DELETE BEGIN; DELETE FROM partitioning_locks WHERE id = 1; ERROR: relation "partitioning_locks" does not exist LINE 1: DELETE FROM partitioning_locks WHERE id = 1; ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on INSERT/SELECT CREATE TABLE partitioning_locks_for_select(id int, ref_id int, time date); SELECT create_distributed_table('partitioning_locks_for_select', 'id'); create_distributed_table -------------------------- (1 row) BEGIN; INSERT INTO partitioning_locks SELECT * FROM partitioning_locks_for_select; ERROR: relation "partitioning_locks" does not exist LINE 1: INSERT INTO partitioning_locks SELECT * FROM partitioning_lo... ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on coordinator INSERT/SELECT BEGIN; INSERT INTO partitioning_locks SELECT * FROM partitioning_locks_for_select LIMIT 5; ERROR: relation "partitioning_locks" does not exist LINE 1: INSERT INTO partitioning_locks SELECT * FROM partitioning_lo... ^ SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on master_modify_multiple_shards BEGIN; SELECT master_modify_multiple_shards('UPDATE partitioning_locks SET time = ''2009-03-01'''); ERROR: relation "partitioning_locks" does not exist SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on DDL BEGIN; ALTER TABLE partitioning_locks ADD COLUMN new_column int; ERROR: relation "partitioning_locks" does not exist SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test locks on TRUNCATE BEGIN; TRUNCATE partitioning_locks; ERROR: relation "partitioning_locks" does not exist SELECT relation::regclass, locktype, mode FROM pg_locks WHERE relation::regclass::text LIKE 'partitioning_locks%' AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test shard resource locks with master_modify_multiple_shards BEGIN; SELECT master_modify_multiple_shards('UPDATE partitioning_locks_2009 SET time = ''2009-03-01'''); ERROR: relation "partitioning_locks_2009" does not exist -- see the locks on parent table SELECT logicalrelid, locktype, mode FROM pg_locks AS l JOIN pg_dist_shard AS s ON l.objid = s.shardid WHERE logicalrelid IN ('partitioning_locks', 'partitioning_locks_2009', 'partitioning_locks_2010') AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test shard resource locks with TRUNCATE BEGIN; TRUNCATE partitioning_locks_2009; ERROR: relation "partitioning_locks_2009" does not exist -- see the locks on parent table SELECT logicalrelid, locktype, mode FROM pg_locks AS l JOIN pg_dist_shard AS s ON l.objid = s.shardid WHERE logicalrelid IN ('partitioning_locks', 'partitioning_locks_2009', 'partitioning_locks_2010') AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test shard resource locks with INSERT/SELECT BEGIN; INSERT INTO partitioning_locks_2009 SELECT * FROM partitioning_locks WHERE time >= '2009-01-01' AND time < '2010-01-01'; ERROR: relation "partitioning_locks_2009" does not exist LINE 1: INSERT INTO partitioning_locks_2009 SELECT * FROM partitioni... ^ -- see the locks on parent table SELECT logicalrelid, locktype, mode FROM pg_locks AS l JOIN pg_dist_shard AS s ON l.objid = s.shardid WHERE logicalrelid IN ('partitioning_locks', 'partitioning_locks_2009', 'partitioning_locks_2010') AND pid = pg_backend_pid() ORDER BY 1, 2, 3; ERROR: current transaction is aborted, commands ignored until end of transaction block COMMIT; -- test partition-wise join CREATE TABLE partitioning_hash_join_test(id int, subid int) PARTITION BY HASH(subid); ERROR: syntax error at or near "PARTITION" LINE 1: ...LE partitioning_hash_join_test(id int, subid int) PARTITION ... ^ CREATE TABLE partitioning_hash_join_test_0 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_hash_join_test_0 PARTITION OF part... ^ CREATE TABLE partitioning_hash_join_test_1 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_hash_join_test_1 PARTITION OF part... ^ CREATE TABLE partitioning_hash_join_test_2 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 2); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_hash_join_test_2 PARTITION OF part... ^ SELECT create_distributed_table('partitioning_hash_join_test', 'id'); ERROR: relation "partitioning_hash_join_test" does not exist LINE 1: SELECT create_distributed_table('partitioning_hash_join_test... ^ -- see the query plan without partition-wise join EXPLAIN SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); ERROR: relation "partitioning_hash_test" does not exist LINE 2: SELECT * FROM partitioning_hash_test JOIN partitioning_hash_... ^ -- set partition-wise join on SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to on'); success --------- f f (2 rows) SELECT success FROM run_command_on_workers('select pg_reload_conf()'); success --------- t t (2 rows) SET enable_partitionwise_join TO on; ERROR: unrecognized configuration parameter "enable_partitionwise_join" -- see the new query plan EXPLAIN SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); ERROR: relation "partitioning_hash_test" does not exist LINE 2: SELECT * FROM partitioning_hash_test JOIN partitioning_hash_... ^ -- note that partition-wise joins only work when partition key is in the join -- following join does not have that, therefore join will not be pushed down to -- partitions EXPLAIN SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); ERROR: relation "partitioning_hash_test" does not exist LINE 2: SELECT * FROM partitioning_hash_test JOIN partitioning_hash_... ^ -- reset partition-wise join SELECT success FROM run_command_on_workers('reset enable_partitionwise_join'); success --------- f f (2 rows) SELECT success FROM run_command_on_workers('select pg_reload_conf()'); success --------- t t (2 rows) RESET enable_partitionwise_join; ERROR: unrecognized configuration parameter "enable_partitionwise_join" DROP TABLE IF EXISTS partitioning_test_2009, partitioned_events_table, partitioned_users_table, list_partitioned_events_table, multi_column_partitioning, partitioning_locks, partitioning_locks_for_select; NOTICE: table "partitioning_test_2009" does not exist, skipping NOTICE: table "partitioned_events_table" does not exist, skipping NOTICE: table "partitioned_users_table" does not exist, skipping NOTICE: table "list_partitioned_events_table" does not exist, skipping NOTICE: table "multi_column_partitioning" does not exist, skipping NOTICE: table "partitioning_locks" does not exist, skipping -- make sure we can create a partitioned table with streaming replication SET citus.replication_model TO 'streaming'; CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test(id int, time date) PARTITION ... ^ CREATE TABLE partitioning_test_2009 PARTITION OF partitioning_test FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: CREATE TABLE partitioning_test_2009 PARTITION OF partitionin... ^ SELECT create_distributed_table('partitioning_test', 'id'); ERROR: relation "partitioning_test" does not exist LINE 1: SELECT create_distributed_table('partitioning_test', 'id'); ^ DROP TABLE partitioning_test; ERROR: table "partitioning_test" does not exist -- make sure we can attach partitions to a distributed table in a schema CREATE SCHEMA partitioning_schema; CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: ...titioning_schema."schema-test"(id int, time date) PARTITION ... ^ SELECT create_distributed_table('partitioning_schema."schema-test"', 'id'); ERROR: relation "partitioning_schema.schema-test" does not exist LINE 1: SELECT create_distributed_table('partitioning_schema."schema... ^ CREATE TABLE partitioning_schema."schema-test_2009"(id int, time date); ALTER TABLE partitioning_schema."schema-test" ATTACH PARTITION partitioning_schema."schema-test_2009" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "ATTACH" LINE 1: ALTER TABLE partitioning_schema."schema-test" ATTACH PARTITI... ^ -- attached partition is distributed as well SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) ORDER BY 1; ERROR: relation "partitioning_schema.schema-test" does not exist LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::regcl... ^ SELECT logicalrelid, count(*) FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) GROUP BY logicalrelid ORDER BY 1,2; ERROR: relation "partitioning_schema.schema-test" does not exist LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::re... ^ DROP TABLE partitioning_schema."schema-test"; ERROR: table "schema-test" does not exist -- make sure we can create partition of a distributed table in a schema CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: ...titioning_schema."schema-test"(id int, time date) PARTITION ... ^ SELECT create_distributed_table('partitioning_schema."schema-test"', 'id'); ERROR: relation "partitioning_schema.schema-test" does not exist LINE 1: SELECT create_distributed_table('partitioning_schema."schema... ^ CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF partitioning_schema."schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: ...EATE TABLE partitioning_schema."schema-test_2009" PARTITION ... ^ -- newly created partition is distributed as well SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) ORDER BY 1; ERROR: relation "partitioning_schema.schema-test" does not exist LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::regcl... ^ SELECT logicalrelid, count(*) FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) GROUP BY logicalrelid ORDER BY 1,2; ERROR: relation "partitioning_schema.schema-test" does not exist LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::re... ^ DROP TABLE partitioning_schema."schema-test"; ERROR: table "schema-test" does not exist -- make sure creating partitioned tables works while search_path is set CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time); ERROR: syntax error at or near "PARTITION" LINE 1: ...titioning_schema."schema-test"(id int, time date) PARTITION ... ^ SET search_path = partitioning_schema; SELECT create_distributed_table('"schema-test"', 'id'); ERROR: relation "schema-test" does not exist LINE 1: SELECT create_distributed_table('"schema-test"', 'id'); ^ CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF "schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); ERROR: syntax error at or near "PARTITION" LINE 1: ...EATE TABLE partitioning_schema."schema-test_2009" PARTITION ... ^ -- newly created partition is distributed as well SELECT logicalrelid FROM pg_dist_partition WHERE logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) ORDER BY 1; ERROR: relation "partitioning_schema.schema-test" does not exist LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::regcl... ^ SELECT logicalrelid, count(*) FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass) GROUP BY logicalrelid ORDER BY 1,2; ERROR: relation "partitioning_schema.schema-test" does not exist LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::re... ^ DROP SCHEMA partitioning_schema CASCADE; NOTICE: drop cascades to table "schema-test_2009" RESET SEARCH_PATH; DROP TABLE IF EXISTS partitioning_hash_test, partitioning_hash_join_test, partitioning_test_failure, non_distributed_partitioned_table, partitioning_test_foreign_key; NOTICE: table "partitioning_hash_test" does not exist, skipping NOTICE: table "partitioning_hash_join_test" does not exist, skipping NOTICE: table "partitioning_test_failure" does not exist, skipping NOTICE: table "non_distributed_partitioned_table" does not exist, skipping