diff --git a/src/backend/distributed/executor/multi_server_executor.c b/src/backend/distributed/executor/multi_server_executor.c index ec3a3af2c..a5cae6e72 100644 --- a/src/backend/distributed/executor/multi_server_executor.c +++ b/src/backend/distributed/executor/multi_server_executor.c @@ -127,18 +127,32 @@ RouterExecutablePlan(MultiPlan *multiPlan, MultiExecutorType executorType) List *workerDependentTaskList = NIL; bool masterQueryHasAggregates = false; - /* TODO: this is a hacky solution to allow 0 shard INSERT ... SELECT */ - if (masterQuery == NULL) - { - return true; - } - - /* router executor cannot execute queries that hit zero shards */ - if (taskCount == 0) + if (executorType == MULTI_EXECUTOR_TASK_TRACKER) { return false; } + /* router executor cannot execute repartition jobs */ + if (dependedJobCount > 0) + { + return false; + } + + /* router executor cannot execute plans when master query is present */ + if (masterQuery != NULL) + { + return false; + } + + /* + * Multi task router executor can execute plans with zero task. This is currently + * here for INSERT ... SELECT queries with zero shards. + */ + if (taskCount == 0) + { + return true; + } + /* check if the first task is a modify or a router task, short-circuit if so */ workerTask = (Task *) linitial(workerTaskList); taskType = workerTask->taskType; @@ -148,18 +162,7 @@ RouterExecutablePlan(MultiPlan *multiPlan, MultiExecutorType executorType) } /* router executor cannot execute SELECT queries that hit more than one shard */ - if (taskCount != 1) - { - return false; - } - - if (executorType == MULTI_EXECUTOR_TASK_TRACKER) - { - return false; - } - - /* router executor cannot execute repartition jobs */ - if (dependedJobCount > 0) + if (taskCount != 1 && taskType == ROUTER_TASK) { return false; } diff --git a/src/test/regress/sql/multi_insert_select.sql b/src/test/regress/sql/multi_insert_select.sql index e04496a60..878654fb1 100644 --- a/src/test/regress/sql/multi_insert_select.sql +++ b/src/test/regress/sql/multi_insert_select.sql @@ -101,6 +101,14 @@ FROM WHERE 0 != 0; +INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) +SELECT + value_2, value_1, value_3, value_4, user_id, time +FROM + raw_events_first +WHERE + user_id = 15 AND user_id = 16; + -- add one more row SET client_min_messages TO INFO; INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES