Fix FULL JOINs again

This commit is contained in:
Igor Nikonov 2024-10-31 12:26:46 +00:00
parent 8245e3d7ef
commit 0808d7f0fb
4 changed files with 16 additions and 11 deletions

View File

@ -1263,6 +1263,7 @@ Planner::Planner(const QueryTreeNodePtr & query_tree_,
findQueryForParallelReplicas(query_tree, select_query_options),
findTableForParallelReplicas(query_tree, select_query_options),
collectFiltersForAnalysis(query_tree, select_query_options))))
, root_planner(true)
{
}
@ -1537,7 +1538,7 @@ void Planner::buildPlanForQueryNode()
JoinTreeQueryPlan join_tree_query_plan;
if (planner_context->getMutableQueryContext()->canUseTaskBasedParallelReplicas()
&& planner_context->getGlobalPlannerContext()->parallel_replicas_node == &query_node)
&& planner_context->getGlobalPlannerContext()->parallel_replicas_node == &query_node && !root_planner)
{
join_tree_query_plan = buildQueryPlanForParallelReplicas(query_node, planner_context, select_query_info.storage_limits);
}

View File

@ -82,6 +82,7 @@ private:
StorageLimitsList storage_limits;
std::set<std::string> used_row_policies;
QueryNodeToPlanStepMapping query_node_to_plan_step_mapping;
bool root_planner = false;
};
}

View File

@ -659,6 +659,7 @@ std::unique_ptr<ExpressionStep> createComputeAliasColumnsStep(
}
JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expression,
const QueryNode & parent_query_node,
const SelectQueryInfo & select_query_info,
const SelectQueryOptions & select_query_options,
PlannerContextPtr & planner_context,
@ -982,7 +983,10 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres
query_plan = std::move(query_plan_parallel_replicas);
}
}
else if (ClusterProxy::canUseParallelReplicasOnInitiator(query_context))
else if (
ClusterProxy::canUseParallelReplicasOnInitiator(query_context)
&& planner_context->getGlobalPlannerContext()->parallel_replicas_node
&& planner_context->getGlobalPlannerContext()->parallel_replicas_node == &parent_query_node)
{
// (1) find read step
QueryPlan::Node * node = query_plan.getRootNode();
@ -1815,6 +1819,7 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node,
const ColumnIdentifierSet & outer_scope_columns,
PlannerContextPtr & planner_context)
{
const QueryNode & parent_query_node = query_node->as<QueryNode &>();
auto table_expressions_stack = buildTableExpressionsStack(query_node->as<QueryNode &>().getJoinTree());
size_t table_expressions_stack_size = table_expressions_stack.size();
bool is_single_table_expression = table_expressions_stack_size == 1;
@ -1850,7 +1855,9 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node,
* Examples: Distributed, LiveView, Merge storages.
*/
auto left_table_expression = table_expressions_stack.front();
auto left_table_expression_query_plan = buildQueryPlanForTableExpression(left_table_expression,
auto left_table_expression_query_plan = buildQueryPlanForTableExpression(
left_table_expression,
parent_query_node,
select_query_info,
select_query_options,
planner_context,
@ -1923,7 +1930,9 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node,
* table expression in subquery.
*/
bool is_remote = planner_context->getTableExpressionDataOrThrow(table_expression).isRemote();
query_plans_stack.push_back(buildQueryPlanForTableExpression(table_expression,
query_plans_stack.push_back(buildQueryPlanForTableExpression(
table_expression,
parent_query_node,
select_query_info,
select_query_options,
planner_context,

View File

@ -101,17 +101,11 @@ std::stack<const QueryNode *> getSupportingParallelReplicasQuery(const IQueryTre
auto join_strictness = join_node.getStrictness();
if (join_kind == JoinKind::Left || (join_kind == JoinKind::Inner && join_strictness == JoinStrictness::All))
{
query_tree_node = join_node.getLeftTableExpression().get();
}
else if (join_kind == JoinKind::Right)
{
query_tree_node = join_node.getRightTableExpression().get();
}
else
{
return {};
}
break;
}
@ -275,7 +269,7 @@ const QueryNode * findQueryForParallelReplicas(const QueryTreeNodePtr & query_tr
/// We don't have any subquery and storage can process parallel replicas by itself.
if (stack.top() == query_tree_node.get())
return nullptr;
return query_node;
/// This is needed to avoid infinite recursion.
auto mutable_context = Context::createCopy(context);