From c6c17b9e3f7017a27ba24043d36fe2db94ef3ada Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Thu, 12 Jan 2023 16:33:00 +0100 Subject: [PATCH] Fixed tests --- src/Planner/PlannerJoinTree.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Planner/PlannerJoinTree.cpp b/src/Planner/PlannerJoinTree.cpp index 8ae39a90252..6a48f322ba5 100644 --- a/src/Planner/PlannerJoinTree.cpp +++ b/src/Planner/PlannerJoinTree.cpp @@ -735,6 +735,7 @@ JoinTreeQueryPlan buildQueryPlanForJoinNode(const QueryTreeNodePtr & join_table_ add_sorting(right_plan, join_clause.key_names_right, JoinTableSide::Right); } + auto join_pipeline_type = join_algorithm->pipelineType(); auto join_step = std::make_unique( left_plan.getCurrentDataStream(), right_plan.getCurrentDataStream(), @@ -743,7 +744,7 @@ JoinTreeQueryPlan buildQueryPlanForJoinNode(const QueryTreeNodePtr & join_table_ settings.max_threads, false /*optimize_read_in_order*/); - join_step->setStepDescription(fmt::format("JOIN {}", join_algorithm->pipelineType())); + join_step->setStepDescription(fmt::format("JOIN {}", join_pipeline_type)); std::vector plans; plans.emplace_back(std::make_unique(std::move(left_plan))); @@ -834,12 +835,26 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node, { const auto & query_node_typed = query_node->as(); auto table_expressions_stack = buildTableExpressionsStack(query_node_typed.getJoinTree()); - bool is_single_table_expression = table_expressions_stack.size() == 1; + size_t table_expressions_stack_size = table_expressions_stack.size(); + bool is_single_table_expression = table_expressions_stack_size == 1; + + std::vector table_expressions_outer_scope_columns(table_expressions_stack_size); + ColumnIdentifierSet current_outer_scope_columns = outer_scope_columns; + + for (Int64 i = table_expressions_stack_size - 1; i >= 0; --i) + { + table_expressions_outer_scope_columns[i] = current_outer_scope_columns; + + if (table_expressions_stack[i]->getNodeType() == QueryTreeNodeType::JOIN) + collectTopLevelColumnIdentifiers(table_expressions_stack[i], planner_context, current_outer_scope_columns); + } std::vector query_plans_stack; - for (auto & table_expression : table_expressions_stack) + for (size_t i = 0; i < table_expressions_stack_size; ++i) { + const auto & table_expression = table_expressions_stack[i]; + if (auto * array_join_node = table_expression->as()) { if (query_plans_stack.empty()) @@ -868,7 +883,7 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node, query_plans_stack.push_back(buildQueryPlanForJoinNode(table_expression, std::move(left_query_plan), std::move(right_query_plan), - outer_scope_columns, + table_expressions_outer_scope_columns[i], planner_context)); } else