mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fix FULL joins
This commit is contained in:
parent
361031f9a3
commit
a6b55563c7
@ -659,7 +659,7 @@ std::unique_ptr<ExpressionStep> createComputeAliasColumnsStep(
|
||||
}
|
||||
|
||||
JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expression,
|
||||
[[maybe_unused]] const QueryNode & parent_query_node,
|
||||
const QueryTreeNodePtr & parent_join_tree,
|
||||
const SelectQueryInfo & select_query_info,
|
||||
const SelectQueryOptions & select_query_options,
|
||||
PlannerContextPtr & planner_context,
|
||||
@ -958,17 +958,22 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres
|
||||
return true;
|
||||
};
|
||||
|
||||
LOG_DEBUG(
|
||||
getLogger(__PRETTY_FUNCTION__),
|
||||
"parallel_replicas_node={} parent_query_node={}",
|
||||
UInt64(planner_context->getGlobalPlannerContext()->parallel_replicas_node),
|
||||
UInt64(&parent_query_node));
|
||||
|
||||
// const JoinNode * table_join_node = parent_query_node.getJoinTree()->as<JoinNode>();
|
||||
|
||||
/// query_plan can be empty if there is nothing to read
|
||||
if (query_plan.isInitialized() && parallel_replicas_enabled_for_storage(storage, settings))
|
||||
{
|
||||
const bool allow_parallel_replicas_for_table_expression = [](const QueryTreeNodePtr & join_tree_node)
|
||||
{
|
||||
const JoinNode * join_node = join_tree_node->as<JoinNode>();
|
||||
if (!join_node)
|
||||
return true;
|
||||
|
||||
const auto join_kind = join_node->getKind();
|
||||
if (join_kind == JoinKind::Left || join_kind == JoinKind::Right || join_kind == JoinKind::Inner)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}(parent_join_tree);
|
||||
|
||||
if (query_context->canUseParallelReplicasCustomKey() && query_context->getClientInfo().distributed_depth == 0)
|
||||
{
|
||||
if (auto cluster = query_context->getClusterForParallelReplicas();
|
||||
@ -991,11 +996,7 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres
|
||||
query_plan = std::move(query_plan_parallel_replicas);
|
||||
}
|
||||
}
|
||||
else if (
|
||||
ClusterProxy::canUseParallelReplicasOnInitiator(query_context))
|
||||
// && (!table_join_node
|
||||
// || (table_join_node && planner_context->getGlobalPlannerContext()->parallel_replicas_node
|
||||
// && planner_context->getGlobalPlannerContext()->parallel_replicas_node == &parent_query_node)))
|
||||
else if (ClusterProxy::canUseParallelReplicasOnInitiator(query_context) && allow_parallel_replicas_for_table_expression)
|
||||
{
|
||||
// (1) find read step
|
||||
QueryPlan::Node * node = query_plan.getRootNode();
|
||||
@ -1828,8 +1829,8 @@ 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());
|
||||
const QueryTreeNodePtr & join_tree_node = query_node->as<QueryNode &>().getJoinTree();
|
||||
auto table_expressions_stack = buildTableExpressionsStack(join_tree_node);
|
||||
size_t table_expressions_stack_size = table_expressions_stack.size();
|
||||
bool is_single_table_expression = table_expressions_stack_size == 1;
|
||||
|
||||
@ -1866,7 +1867,7 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node,
|
||||
auto left_table_expression = table_expressions_stack.front();
|
||||
auto left_table_expression_query_plan = buildQueryPlanForTableExpression(
|
||||
left_table_expression,
|
||||
parent_query_node,
|
||||
join_tree_node,
|
||||
select_query_info,
|
||||
select_query_options,
|
||||
planner_context,
|
||||
@ -1941,7 +1942,7 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node,
|
||||
bool is_remote = planner_context->getTableExpressionDataOrThrow(table_expression).isRemote();
|
||||
query_plans_stack.push_back(buildQueryPlanForTableExpression(
|
||||
table_expression,
|
||||
parent_query_node,
|
||||
join_tree_node,
|
||||
select_query_info,
|
||||
select_query_options,
|
||||
planner_context,
|
||||
|
@ -88,6 +88,34 @@ right subs
|
||||
4 l5 \N 4 r6 nr6
|
||||
4 l6 \N 4 r6 nr6
|
||||
9 l9 \N 9 r9 nr9
|
||||
full
|
||||
0 \N 6 r7 nr7
|
||||
0 \N 7 r8 nr8
|
||||
1 l1 1 1 r1 \N
|
||||
1 l1 1 1 r2 \N
|
||||
2 l2 2 2 r3 \N
|
||||
2 l3 3 2 r3 \N
|
||||
3 l4 4 3 r4 \N
|
||||
3 l4 4 3 r5 \N
|
||||
4 l5 \N 4 r6 nr6
|
||||
4 l6 \N 4 r6 nr6
|
||||
5 l7 \N 0 \N
|
||||
8 l8 \N 0 \N
|
||||
9 l9 \N 9 r9 nr9
|
||||
full subs
|
||||
0 \N 6 r7 nr7
|
||||
0 \N 7 r8 nr8
|
||||
1 l1 1 1 r1 \N
|
||||
1 l1 1 1 r2 \N
|
||||
2 l2 2 2 r3 \N
|
||||
2 l3 3 2 r3 \N
|
||||
3 l4 4 3 r4 \N
|
||||
3 l4 4 3 r5 \N
|
||||
4 l5 \N 4 r6 nr6
|
||||
4 l6 \N 4 r6 nr6
|
||||
5 l7 \N 0 \N
|
||||
8 l8 \N 0 \N
|
||||
9 l9 \N 9 r9 nr9
|
||||
self inner
|
||||
1 l1 1 1 l1 1
|
||||
2 l2 2 2 l2 2
|
||||
@ -199,3 +227,47 @@ self right nullable vs not nullable
|
||||
3 l4 4 2 l3 3
|
||||
4 l5 \N 3 l4 4
|
||||
4 l6 \N 3 l4 4
|
||||
self full
|
||||
1 l1 1 1 l1 1
|
||||
2 l2 2 2 l2 2
|
||||
2 l2 2 2 l3 3
|
||||
2 l3 3 2 l2 2
|
||||
2 l3 3 2 l3 3
|
||||
3 l4 4 3 l4 4
|
||||
4 l5 \N 4 l5 \N
|
||||
4 l5 \N 4 l6 \N
|
||||
4 l6 \N 4 l5 \N
|
||||
4 l6 \N 4 l6 \N
|
||||
5 l7 \N 5 l7 \N
|
||||
8 l8 \N 8 l8 \N
|
||||
9 l9 \N 9 l9 \N
|
||||
self full nullable
|
||||
0 \N 4 l5 \N
|
||||
0 \N 4 l6 \N
|
||||
0 \N 5 l7 \N
|
||||
0 \N 8 l8 \N
|
||||
0 \N 9 l9 \N
|
||||
1 l1 1 1 l1 1
|
||||
2 l2 2 2 l2 2
|
||||
2 l3 3 2 l3 3
|
||||
3 l4 4 3 l4 4
|
||||
4 l5 \N 0 \N
|
||||
4 l6 \N 0 \N
|
||||
5 l7 \N 0 \N
|
||||
8 l8 \N 0 \N
|
||||
9 l9 \N 0 \N
|
||||
self full nullable vs not nullable
|
||||
0 \N 4 l5 \N
|
||||
0 \N 4 l6 \N
|
||||
0 \N 5 l7 \N
|
||||
0 \N 8 l8 \N
|
||||
0 \N 9 l9 \N
|
||||
1 l1 1 1 l1 1
|
||||
2 l2 2 2 l2 2
|
||||
2 l3 3 2 l2 2
|
||||
3 l4 4 2 l3 3
|
||||
4 l5 \N 3 l4 4
|
||||
4 l6 \N 3 l4 4
|
||||
5 l7 \N 0 \N
|
||||
8 l8 \N 0 \N
|
||||
9 l9 \N 0 \N
|
||||
|
@ -30,6 +30,11 @@ select X.*, Y.* from X right join Y on X.id = Y.id order by X.id, X.x_a, X.x_b,
|
||||
select 'right subs';
|
||||
select s.*, j.* from (select * from X) as s right join (select * from Y) as j on s.id = j.id order by s.id, s.x_a, s.x_b, j.id, j.y_a, j.y_b;
|
||||
|
||||
select 'full';
|
||||
select X.*, Y.* from X full join Y on X.id = Y.id order by X.id, X.x_a, X.x_b, Y.id, Y.y_a, Y.y_b;
|
||||
select 'full subs';
|
||||
select s.*, j.* from (select * from X) as s full join (select * from Y) as j on s.id = j.id order by s.id, s.x_a, s.x_b, j.id, j.y_a, j.y_b;
|
||||
|
||||
select 'self inner';
|
||||
select X.*, s.* from X inner join (select * from X) as s on X.id = s.id order by X.id, X.x_a, X.x_b, s.id, s.x_a, s.x_b;
|
||||
select 'self inner nullable';
|
||||
@ -55,5 +60,12 @@ select X.*, s.* from X right join (select * from X) as s on X.x_b = s.x_b order
|
||||
select 'self right nullable vs not nullable';
|
||||
select X.*, s.* from X right join (select * from X) as s on X.id = s.x_b order by X.id, X.x_a, X.x_b, s.id, s.x_a, s.x_b;
|
||||
|
||||
select 'self full';
|
||||
select X.*, s.* from X full join (select * from X) as s on X.id = s.id order by X.id, X.x_a, X.x_b, s.id, s.x_a, s.x_b;
|
||||
select 'self full nullable';
|
||||
select X.*, s.* from X full join (select * from X) as s on X.x_b = s.x_b order by X.id, X.x_a, X.x_b, s.id, s.x_a, s.x_b;
|
||||
select 'self full nullable vs not nullable';
|
||||
select X.*, s.* from X full join (select * from X) as s on X.id = s.x_b order by X.id, X.x_a, X.x_b, s.id, s.x_a, s.x_b;
|
||||
|
||||
drop table X sync;
|
||||
drop table Y sync;
|
||||
|
Loading…
Reference in New Issue
Block a user