diff --git a/src/Interpreters/ClusterProxy/executeQuery.cpp b/src/Interpreters/ClusterProxy/executeQuery.cpp index c0d156a8894..a8cf3022a61 100644 --- a/src/Interpreters/ClusterProxy/executeQuery.cpp +++ b/src/Interpreters/ClusterProxy/executeQuery.cpp @@ -528,7 +528,7 @@ void executeQueryWithParallelReplicas( /// do not build local plan for distributed queries for now (address it later) if (settings.allow_experimental_analyzer && settings.parallel_replicas_local_plan && !shard_num) { - auto local_plan = createLocalPlanForParallelReplicas( + auto [local_plan, with_parallel_replicas] = createLocalPlanForParallelReplicas( query_ast, header, new_context, @@ -536,6 +536,12 @@ void executeQueryWithParallelReplicas( coordinator, std::move(analyzed_read_from_merge_tree)); + if (!with_parallel_replicas) + { + query_plan = std::move(*local_plan); + return; + } + auto read_from_remote = std::make_unique( query_ast, new_cluster, diff --git a/src/Processors/QueryPlan/ParallelReplicasLocalPlan.cpp b/src/Processors/QueryPlan/ParallelReplicasLocalPlan.cpp index d2e862a3416..e9d5ef90e30 100644 --- a/src/Processors/QueryPlan/ParallelReplicasLocalPlan.cpp +++ b/src/Processors/QueryPlan/ParallelReplicasLocalPlan.cpp @@ -21,9 +21,7 @@ namespace DB { -void addConvertingActions(QueryPlan & plan, const Block & header, bool has_missing_objects); - -std::unique_ptr createLocalPlanForParallelReplicas( +std::pair, bool> createLocalPlanForParallelReplicas( const ASTPtr & query_ast, const Block & header, ContextPtr context, @@ -68,7 +66,9 @@ std::unique_ptr createLocalPlanForParallelReplicas( node = nullptr; } - chassert(reading); + if (!reading) + /// it can happened if merge tree table is empty, - it'll be replaced with ReadFromPreparedSource + return {std::move(query_plan), false}; ReadFromMergeTree::AnalysisResultPtr analyzed_result_ptr; if (analyzed_read_from_merge_tree.get()) @@ -89,7 +89,8 @@ std::unique_ptr createLocalPlanForParallelReplicas( node->step = std::move(read_from_merge_tree_parallel_replicas); addConvertingActions(*query_plan, header, /*has_missing_objects=*/false); - return query_plan; + + return {std::move(query_plan), true}; } } diff --git a/src/Processors/QueryPlan/ParallelReplicasLocalPlan.h b/src/Processors/QueryPlan/ParallelReplicasLocalPlan.h index 123754458a1..2a49be6347a 100644 --- a/src/Processors/QueryPlan/ParallelReplicasLocalPlan.h +++ b/src/Processors/QueryPlan/ParallelReplicasLocalPlan.h @@ -8,7 +8,7 @@ namespace DB { -std::unique_ptr createLocalPlanForParallelReplicas( +std::pair, bool> createLocalPlanForParallelReplicas( const ASTPtr & query_ast, const Block & header, ContextPtr context,