Fix: fallback to local plan w/o PR in case of empty table

This commit is contained in:
Igor Nikonov 2024-07-17 11:45:00 +00:00
parent a3d4fd9246
commit baf3408b16
3 changed files with 14 additions and 7 deletions

View File

@ -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<ReadFromParallelRemoteReplicasStep>(
query_ast,
new_cluster,

View File

@ -21,9 +21,7 @@
namespace DB
{
void addConvertingActions(QueryPlan & plan, const Block & header, bool has_missing_objects);
std::unique_ptr<QueryPlan> createLocalPlanForParallelReplicas(
std::pair<std::unique_ptr<QueryPlan>, bool> createLocalPlanForParallelReplicas(
const ASTPtr & query_ast,
const Block & header,
ContextPtr context,
@ -68,7 +66,9 @@ std::unique_ptr<QueryPlan> 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<QueryPlan> 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};
}
}

View File

@ -8,7 +8,7 @@
namespace DB
{
std::unique_ptr<QueryPlan> createLocalPlanForParallelReplicas(
std::pair<std::unique_ptr<QueryPlan>, bool> createLocalPlanForParallelReplicas(
const ASTPtr & query_ast,
const Block & header,
ContextPtr context,