From 6b65dbc492d937a37b536fc8555881328f52ebbb Mon Sep 17 00:00:00 2001 From: Sait Talha Nisanci Date: Fri, 20 Aug 2021 09:38:41 +0300 Subject: [PATCH] Add partition_wise_join to avoid big alternative output There was a small part in multi_partitioning that would need an alternative output for pg14. Instead of adding an alternative for the whole file, we created a new file, called partition_wise_join.sql and added the alternative output for that. --- .../regress/expected/multi_partitioning.out | 192 +--------------- .../regress/expected/partition_wise_join.out | 208 ++++++++++++++++++ .../expected/partition_wise_join_0.out | 208 ++++++++++++++++++ src/test/regress/multi_1_schedule | 1 + src/test/regress/sql/multi_partitioning.sql | 45 ---- src/test/regress/sql/partition_wise_join.sql | 61 +++++ 6 files changed, 479 insertions(+), 236 deletions(-) create mode 100644 src/test/regress/expected/partition_wise_join.out create mode 100644 src/test/regress/expected/partition_wise_join_0.out create mode 100644 src/test/regress/sql/partition_wise_join.sql diff --git a/src/test/regress/expected/multi_partitioning.out b/src/test/regress/expected/multi_partitioning.out index 310436b41..9980b0f85 100644 --- a/src/test/regress/expected/multi_partitioning.out +++ b/src/test/regress/expected/multi_partitioning.out @@ -1616,194 +1616,6 @@ SELECT * FROM lockinfo; (20 rows) COMMIT; --- test partition-wise join -CREATE TABLE partitioning_hash_join_test(id int, subid int) PARTITION BY HASH(subid); -CREATE TABLE partitioning_hash_join_test_0 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); -CREATE TABLE partitioning_hash_join_test_1 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); -CREATE TABLE partitioning_hash_join_test_2 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 2); -SELECT create_distributed_table('partitioning_hash_join_test', 'id'); - create_distributed_table ---------------------------------------------------------------------- - -(1 row) - -SELECT success FROM run_command_on_workers('alter system set enable_mergejoin to off'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_nestloop to off'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_indexscan to off'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_indexonlyscan to off'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to off'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -EXPLAIN (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); - QUERY PLAN ---------------------------------------------------------------------- - Custom Scan (Citus Adaptive) - Task Count: 4 - Tasks Shown: One of 4 - -> Task - Node: host=localhost port=xxxxx dbname=regression - -> Hash Join - Hash Cond: ((partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) AND (partitioning_hash_join_test_xxx.subid = partitioning_hash_test_xxx.subid)) - -> Append - -> Seq Scan on partitioning_hash_join_test_0_1660133 partitioning_hash_join_test_xxx - -> Seq Scan on partitioning_hash_join_test_1_1660137 partitioning_hash_join_test_xxx - -> Seq Scan on partitioning_hash_join_test_2_1660141 partitioning_hash_join_test_xxx - -> Hash - -> Append - -> Seq Scan on partitioning_hash_test_0_1660016 partitioning_hash_test_xxx - -> Seq Scan on partitioning_hash_test_1_1660020 partitioning_hash_test_xxx - -> Seq Scan on partitioning_hash_test_2_1660032 partitioning_hash_test_xxx -(16 rows) - --- set partition-wise join on and parallel to off -SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to on'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SET enable_partitionwise_join TO on; -ANALYZE partitioning_hash_test, partitioning_hash_join_test; -EXPLAIN (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); - QUERY PLAN ---------------------------------------------------------------------- - Custom Scan (Citus Adaptive) - Task Count: 4 - Tasks Shown: One of 4 - -> Task - Node: host=localhost port=xxxxx dbname=regression - -> Append - -> Hash Join - Hash Cond: ((partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) AND (partitioning_hash_join_test_xxx.subid = partitioning_hash_test_xxx.subid)) - -> Seq Scan on partitioning_hash_join_test_0_1660133 partitioning_hash_join_test_xxx - -> Hash - -> Seq Scan on partitioning_hash_test_0_1660016 partitioning_hash_test_xxx - -> Hash Join - Hash Cond: ((partitioning_hash_test_xxx.id = partitioning_hash_join_test_xxx.id) AND (partitioning_hash_test_xxx.subid = partitioning_hash_join_test_xxx.subid)) - -> Seq Scan on partitioning_hash_test_1_1660020 partitioning_hash_test_xxx - -> Hash - -> Seq Scan on partitioning_hash_join_test_1_1660137 partitioning_hash_join_test_xxx - -> Hash Join - Hash Cond: ((partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) AND (partitioning_hash_join_test_xxx.subid = partitioning_hash_test_xxx.subid)) - -> Seq Scan on partitioning_hash_join_test_2_1660141 partitioning_hash_join_test_xxx - -> Hash - -> Seq Scan on partitioning_hash_test_2_1660032 partitioning_hash_test_xxx -(21 rows) - --- 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 (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); - QUERY PLAN ---------------------------------------------------------------------- - Custom Scan (Citus Adaptive) - Task Count: 4 - Tasks Shown: One of 4 - -> Task - Node: host=localhost port=xxxxx dbname=regression - -> Hash Join - Hash Cond: (partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) - -> Append - -> Seq Scan on partitioning_hash_join_test_0_1660133 partitioning_hash_join_test_xxx - -> Seq Scan on partitioning_hash_join_test_1_1660137 partitioning_hash_join_test_xxx - -> Seq Scan on partitioning_hash_join_test_2_1660141 partitioning_hash_join_test_xxx - -> Hash - -> Append - -> Seq Scan on partitioning_hash_test_0_1660016 partitioning_hash_test_xxx - -> Seq Scan on partitioning_hash_test_1_1660020 partitioning_hash_test_xxx - -> Seq Scan on partitioning_hash_test_2_1660032 partitioning_hash_test_xxx -(16 rows) - --- reset partition-wise join -SELECT success FROM run_command_on_workers('alter system reset enable_partitionwise_join'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_mergejoin'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_nestloop'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_indexscan'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('alter system reset enable_indexonlyscan'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - success ---------------------------------------------------------------------- - t - t -(2 rows) - -RESET enable_partitionwise_join; DROP VIEW lockinfo; DROP TABLE IF EXISTS @@ -2069,10 +1881,9 @@ SELECT fix_pre_citus10_partitioned_table_constraint_names(); --------------------------------------------------------------------- partitioning_test "schema-test" - public.partitioning_hash_join_test public.partitioning_hash_test public.partitioning_test_failure -(5 rows) +(4 rows) -- the following should fail SELECT fix_pre_citus10_partitioned_table_constraint_names('public.non_distributed_partitioned_table'); @@ -2248,7 +2059,6 @@ drop cascades to table distributed_parent_table 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; diff --git a/src/test/regress/expected/partition_wise_join.out b/src/test/regress/expected/partition_wise_join.out new file mode 100644 index 000000000..1b00fcef3 --- /dev/null +++ b/src/test/regress/expected/partition_wise_join.out @@ -0,0 +1,208 @@ +CREATE SCHEMA partition_wise_join; +SET search_path to partition_wise_join; +CREATE TABLE partitioning_hash_test(id int, subid int) PARTITION BY HASH(subid); +CREATE TABLE partitioning_hash_test_0 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); +CREATE TABLE partitioning_hash_test_1 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); +INSERT INTO partitioning_hash_test VALUES (1, 2); +INSERT INTO partitioning_hash_test VALUES (2, 13); +INSERT INTO partitioning_hash_test VALUES (3, 7); +INSERT INTO partitioning_hash_test VALUES (4, 4); +-- distribute partitioned table +SELECT create_distributed_table('partitioning_hash_test', 'id'); +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($$partition_wise_join.partitioning_hash_test_0$$) +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($$partition_wise_join.partitioning_hash_test_1$$) + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +-- test partition-wise join +CREATE TABLE partitioning_hash_join_test(id int, subid int) PARTITION BY HASH(subid); +CREATE TABLE partitioning_hash_join_test_0 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); +CREATE TABLE partitioning_hash_join_test_1 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); +CREATE TABLE partitioning_hash_join_test_2 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 2); +SELECT create_distributed_table('partitioning_hash_join_test', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +SELECT success FROM run_command_on_workers('alter system set enable_mergejoin to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_nestloop to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_indexscan to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_indexonlyscan to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +EXPLAIN (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); + QUERY PLAN +--------------------------------------------------------------------- + Custom Scan (Citus Adaptive) + Task Count: 4 + Tasks Shown: One of 4 + -> Task + Node: host=localhost port=xxxxx dbname=regression + -> Hash Join + Hash Cond: ((partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) AND (partitioning_hash_join_test_xxx.subid = partitioning_hash_test_xxx.subid)) + -> Append + -> Seq Scan on partitioning_hash_join_test_0_360163 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_1_360167 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_2_360171 partitioning_hash_join_test_xxx + -> Hash + -> Append + -> Seq Scan on partitioning_hash_test_0_360151 partitioning_hash_test_xxx + -> Seq Scan on partitioning_hash_test_1_360155 partitioning_hash_test_xxx +(15 rows) + +-- set partition-wise join on and parallel to off +SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to on'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +-- SET enable_partitionwise_join TO on; +ANALYZE partitioning_hash_test, partitioning_hash_join_test; +EXPLAIN (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); + QUERY PLAN +--------------------------------------------------------------------- + Custom Scan (Citus Adaptive) + Task Count: 4 + Tasks Shown: One of 4 + -> Task + Node: host=localhost port=xxxxx dbname=regression + -> Hash Join + Hash Cond: ((partitioning_hash_test_xxx.id = partitioning_hash_join_test_xxx.id) AND (partitioning_hash_test_xxx.subid = partitioning_hash_join_test_xxx.subid)) + -> Append + -> Seq Scan on partitioning_hash_test_0_360151 partitioning_hash_test_xxx + -> Seq Scan on partitioning_hash_test_1_360155 partitioning_hash_test_xxx + -> Hash + -> Append + -> Seq Scan on partitioning_hash_join_test_0_360163 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_1_360167 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_2_360171 partitioning_hash_join_test_xxx +(15 rows) + +-- 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 (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); + QUERY PLAN +--------------------------------------------------------------------- + Custom Scan (Citus Adaptive) + Task Count: 4 + Tasks Shown: One of 4 + -> Task + Node: host=localhost port=xxxxx dbname=regression + -> Hash Join + Hash Cond: (partitioning_hash_test_xxx.id = partitioning_hash_join_test_xxx.id) + -> Append + -> Seq Scan on partitioning_hash_test_0_360151 partitioning_hash_test_xxx + -> Seq Scan on partitioning_hash_test_1_360155 partitioning_hash_test_xxx + -> Hash + -> Append + -> Seq Scan on partitioning_hash_join_test_0_360163 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_1_360167 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_2_360171 partitioning_hash_join_test_xxx +(15 rows) + +-- reset partition-wise join +SELECT success FROM run_command_on_workers('alter system reset enable_partitionwise_join'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_mergejoin'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_nestloop'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_indexscan'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_indexonlyscan'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +RESET enable_partitionwise_join; +DROP SCHEMA partition_wise_join CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table partitioning_hash_test +drop cascades to table partitioning_hash_join_test diff --git a/src/test/regress/expected/partition_wise_join_0.out b/src/test/regress/expected/partition_wise_join_0.out new file mode 100644 index 000000000..9bda58598 --- /dev/null +++ b/src/test/regress/expected/partition_wise_join_0.out @@ -0,0 +1,208 @@ +CREATE SCHEMA partition_wise_join; +SET search_path to partition_wise_join; +CREATE TABLE partitioning_hash_test(id int, subid int) PARTITION BY HASH(subid); +CREATE TABLE partitioning_hash_test_0 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); +CREATE TABLE partitioning_hash_test_1 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); +INSERT INTO partitioning_hash_test VALUES (1, 2); +INSERT INTO partitioning_hash_test VALUES (2, 13); +INSERT INTO partitioning_hash_test VALUES (3, 7); +INSERT INTO partitioning_hash_test VALUES (4, 4); +-- distribute partitioned table +SELECT create_distributed_table('partitioning_hash_test', 'id'); +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($$partition_wise_join.partitioning_hash_test_0$$) +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($$partition_wise_join.partitioning_hash_test_1$$) + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +-- test partition-wise join +CREATE TABLE partitioning_hash_join_test(id int, subid int) PARTITION BY HASH(subid); +CREATE TABLE partitioning_hash_join_test_0 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); +CREATE TABLE partitioning_hash_join_test_1 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); +CREATE TABLE partitioning_hash_join_test_2 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 2); +SELECT create_distributed_table('partitioning_hash_join_test', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +SELECT success FROM run_command_on_workers('alter system set enable_mergejoin to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_nestloop to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_indexscan to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_indexonlyscan to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to off'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +EXPLAIN (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); + QUERY PLAN +--------------------------------------------------------------------- + Custom Scan (Citus Adaptive) + Task Count: 4 + Tasks Shown: One of 4 + -> Task + Node: host=localhost port=xxxxx dbname=regression + -> Hash Join + Hash Cond: ((partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) AND (partitioning_hash_join_test_xxx.subid = partitioning_hash_test_xxx.subid)) + -> Append + -> Seq Scan on partitioning_hash_join_test_0_360163 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_1_360167 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_2_360171 partitioning_hash_join_test_xxx + -> Hash + -> Append + -> Seq Scan on partitioning_hash_test_0_360151 partitioning_hash_test_xxx + -> Seq Scan on partitioning_hash_test_1_360155 partitioning_hash_test_xxx +(15 rows) + +-- set partition-wise join on and parallel to off +SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to on'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +-- SET enable_partitionwise_join TO on; +ANALYZE partitioning_hash_test, partitioning_hash_join_test; +EXPLAIN (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); + QUERY PLAN +--------------------------------------------------------------------- + Custom Scan (Citus Adaptive) + Task Count: 4 + Tasks Shown: One of 4 + -> Task + Node: host=localhost port=xxxxx dbname=regression + -> Hash Join + Hash Cond: ((partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) AND (partitioning_hash_join_test_xxx.subid = partitioning_hash_test_xxx.subid)) + -> Append + -> Seq Scan on partitioning_hash_join_test_0_360163 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_1_360167 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_2_360171 partitioning_hash_join_test_xxx + -> Hash + -> Append + -> Seq Scan on partitioning_hash_test_0_360151 partitioning_hash_test_xxx + -> Seq Scan on partitioning_hash_test_1_360155 partitioning_hash_test_xxx +(15 rows) + +-- 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 (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); + QUERY PLAN +--------------------------------------------------------------------- + Custom Scan (Citus Adaptive) + Task Count: 4 + Tasks Shown: One of 4 + -> Task + Node: host=localhost port=xxxxx dbname=regression + -> Hash Join + Hash Cond: (partitioning_hash_join_test_xxx.id = partitioning_hash_test_xxx.id) + -> Append + -> Seq Scan on partitioning_hash_join_test_0_360163 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_1_360167 partitioning_hash_join_test_xxx + -> Seq Scan on partitioning_hash_join_test_2_360171 partitioning_hash_join_test_xxx + -> Hash + -> Append + -> Seq Scan on partitioning_hash_test_0_360151 partitioning_hash_test_xxx + -> Seq Scan on partitioning_hash_test_1_360155 partitioning_hash_test_xxx +(15 rows) + +-- reset partition-wise join +SELECT success FROM run_command_on_workers('alter system reset enable_partitionwise_join'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_mergejoin'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_nestloop'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_indexscan'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('alter system reset enable_indexonlyscan'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + success +--------------------------------------------------------------------- + t + t +(2 rows) + +RESET enable_partitionwise_join; +DROP SCHEMA partition_wise_join CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table partitioning_hash_test +drop cascades to table partitioning_hash_join_test diff --git a/src/test/regress/multi_1_schedule b/src/test/regress/multi_1_schedule index ef09cb0db..266ee3e12 100644 --- a/src/test/regress/multi_1_schedule +++ b/src/test/regress/multi_1_schedule @@ -67,6 +67,7 @@ test: ensure_no_intermediate_data_leak # ---------- test: multi_partitioning_utils multi_partitioning partitioning_issue_3970 replicated_partitioned_table test: drop_partitioned_table +test: partition_wise_join # ---------- # Tests for foreign data wrapper support diff --git a/src/test/regress/sql/multi_partitioning.sql b/src/test/regress/sql/multi_partitioning.sql index ae48314dd..b480dd7b3 100644 --- a/src/test/regress/sql/multi_partitioning.sql +++ b/src/test/regress/sql/multi_partitioning.sql @@ -1020,50 +1020,6 @@ INSERT INTO partitioning_locks_2009 SELECT * FROM partitioning_locks WHERE time SELECT * FROM lockinfo; COMMIT; --- test partition-wise join -CREATE TABLE partitioning_hash_join_test(id int, subid int) PARTITION BY HASH(subid); -CREATE TABLE partitioning_hash_join_test_0 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); -CREATE TABLE partitioning_hash_join_test_1 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); -CREATE TABLE partitioning_hash_join_test_2 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 2); - -SELECT create_distributed_table('partitioning_hash_join_test', 'id'); - -SELECT success FROM run_command_on_workers('alter system set enable_mergejoin to off'); -SELECT success FROM run_command_on_workers('alter system set enable_nestloop to off'); -SELECT success FROM run_command_on_workers('alter system set enable_indexscan to off'); -SELECT success FROM run_command_on_workers('alter system set enable_indexonlyscan to off'); -SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to off'); -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - -EXPLAIN (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); - --- set partition-wise join on and parallel to off -SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to on'); -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - -SET enable_partitionwise_join TO on; -ANALYZE partitioning_hash_test, partitioning_hash_join_test; - -EXPLAIN (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); - --- 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 (COSTS OFF) -SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); - --- reset partition-wise join -SELECT success FROM run_command_on_workers('alter system reset enable_partitionwise_join'); -SELECT success FROM run_command_on_workers('alter system reset enable_mergejoin'); -SELECT success FROM run_command_on_workers('alter system reset enable_nestloop'); -SELECT success FROM run_command_on_workers('alter system reset enable_indexscan'); -SELECT success FROM run_command_on_workers('alter system reset enable_indexonlyscan'); -SELECT success FROM run_command_on_workers('select pg_reload_conf()'); - -RESET enable_partitionwise_join; - DROP VIEW lockinfo; DROP TABLE IF EXISTS @@ -1328,7 +1284,6 @@ DROP SCHEMA partitioning_schema CASCADE; 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; diff --git a/src/test/regress/sql/partition_wise_join.sql b/src/test/regress/sql/partition_wise_join.sql new file mode 100644 index 000000000..38e6d7a0b --- /dev/null +++ b/src/test/regress/sql/partition_wise_join.sql @@ -0,0 +1,61 @@ +CREATE SCHEMA partition_wise_join; +SET search_path to partition_wise_join; + +CREATE TABLE partitioning_hash_test(id int, subid int) PARTITION BY HASH(subid); + +CREATE TABLE partitioning_hash_test_0 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); +CREATE TABLE partitioning_hash_test_1 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); + +INSERT INTO partitioning_hash_test VALUES (1, 2); +INSERT INTO partitioning_hash_test VALUES (2, 13); +INSERT INTO partitioning_hash_test VALUES (3, 7); +INSERT INTO partitioning_hash_test VALUES (4, 4); + +-- distribute partitioned table +SELECT create_distributed_table('partitioning_hash_test', 'id'); + +-- test partition-wise join +CREATE TABLE partitioning_hash_join_test(id int, subid int) PARTITION BY HASH(subid); +CREATE TABLE partitioning_hash_join_test_0 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 0); +CREATE TABLE partitioning_hash_join_test_1 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 1); +CREATE TABLE partitioning_hash_join_test_2 PARTITION OF partitioning_hash_join_test FOR VALUES WITH (MODULUS 3, REMAINDER 2); + +SELECT create_distributed_table('partitioning_hash_join_test', 'id'); + +SELECT success FROM run_command_on_workers('alter system set enable_mergejoin to off'); +SELECT success FROM run_command_on_workers('alter system set enable_nestloop to off'); +SELECT success FROM run_command_on_workers('alter system set enable_indexscan to off'); +SELECT success FROM run_command_on_workers('alter system set enable_indexonlyscan to off'); +SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to off'); +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + +EXPLAIN (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); + +-- set partition-wise join on and parallel to off +SELECT success FROM run_command_on_workers('alter system set enable_partitionwise_join to on'); +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + +-- SET enable_partitionwise_join TO on; +ANALYZE partitioning_hash_test, partitioning_hash_join_test; + +EXPLAIN (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id, subid); + +-- 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 (COSTS OFF) +SELECT * FROM partitioning_hash_test JOIN partitioning_hash_join_test USING (id); + +-- reset partition-wise join +SELECT success FROM run_command_on_workers('alter system reset enable_partitionwise_join'); +SELECT success FROM run_command_on_workers('alter system reset enable_mergejoin'); +SELECT success FROM run_command_on_workers('alter system reset enable_nestloop'); +SELECT success FROM run_command_on_workers('alter system reset enable_indexscan'); +SELECT success FROM run_command_on_workers('alter system reset enable_indexonlyscan'); +SELECT success FROM run_command_on_workers('select pg_reload_conf()'); + +RESET enable_partitionwise_join; + +DROP SCHEMA partition_wise_join CASCADE; \ No newline at end of file