diff --git a/src/backend/distributed/executor/insert_select_executor.c b/src/backend/distributed/executor/insert_select_executor.c index 8547c21c2..14e781be5 100644 --- a/src/backend/distributed/executor/insert_select_executor.c +++ b/src/backend/distributed/executor/insert_select_executor.c @@ -1057,6 +1057,12 @@ IsRedistributablePlan(Plan *selectPlan) return false; } + /* don't use redistribution for repartition joins for now */ + if (distSelectJob->dependentJobList != NIL) + { + return false; + } + return true; } diff --git a/src/test/regress/expected/insert_select_repartition.out b/src/test/regress/expected/insert_select_repartition.out index bc50ab93c..65d374e70 100644 --- a/src/test/regress/expected/insert_select_repartition.out +++ b/src/test/regress/expected/insert_select_repartition.out @@ -978,5 +978,21 @@ EXPLAIN (costs off) INSERT INTO target_table SELECT a AS aa, b AS aa, 1 AS aa, 2 (8 rows) DROP TABLE source_table, target_table; +-- +-- Don't use INSERT/SELECT repartition with repartition joins +-- +create table test(x int, y int); +select create_distributed_table('test', 'x'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +set citus.enable_repartition_joins to true; +SET client_min_messages TO DEBUG1; +insert into test(y, x) select a.x, b.y from test a JOIN test b USING (y); +DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match +DEBUG: Collecting INSERT ... SELECT results on coordinator +RESET client_min_messages; SET client_min_messages TO WARNING; DROP SCHEMA insert_select_repartition CASCADE; diff --git a/src/test/regress/sql/insert_select_repartition.sql b/src/test/regress/sql/insert_select_repartition.sql index 127980686..e6f4bfa87 100644 --- a/src/test/regress/sql/insert_select_repartition.sql +++ b/src/test/regress/sql/insert_select_repartition.sql @@ -452,5 +452,17 @@ EXPLAIN (costs off) INSERT INTO target_table SELECT a AS aa, b AS aa, 1 AS aa, 2 DROP TABLE source_table, target_table; +-- +-- Don't use INSERT/SELECT repartition with repartition joins +-- + +create table test(x int, y int); +select create_distributed_table('test', 'x'); +set citus.enable_repartition_joins to true; + +SET client_min_messages TO DEBUG1; +insert into test(y, x) select a.x, b.y from test a JOIN test b USING (y); +RESET client_min_messages; + SET client_min_messages TO WARNING; DROP SCHEMA insert_select_repartition CASCADE;