mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
fix COMMA and other JOIN mix (#10311)
This commit is contained in:
parent
d5b3b2c7b6
commit
c62c288e4c
@ -52,17 +52,21 @@ struct JoinedElement
|
|||||||
|
|
||||||
void rewriteCommaToCross()
|
void rewriteCommaToCross()
|
||||||
{
|
{
|
||||||
if (join)
|
if (join && join->kind == ASTTableJoin::Kind::Comma)
|
||||||
join->kind = ASTTableJoin::Kind::Cross;
|
join->kind = ASTTableJoin::Kind::Cross;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewriteCrossToInner(ASTPtr on_expression)
|
bool rewriteCrossToInner(ASTPtr on_expression)
|
||||||
{
|
{
|
||||||
|
if (join->kind != ASTTableJoin::Kind::Cross)
|
||||||
|
return false;
|
||||||
|
|
||||||
join->kind = ASTTableJoin::Kind::Inner;
|
join->kind = ASTTableJoin::Kind::Inner;
|
||||||
join->strictness = ASTTableJoin::Strictness::All;
|
join->strictness = ASTTableJoin::Strictness::All;
|
||||||
|
|
||||||
join->on_expression = on_expression;
|
join->on_expression = on_expression;
|
||||||
join->children.push_back(join->on_expression);
|
join->children.push_back(join->on_expression);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPtr arrayJoin() const { return element.array_join; }
|
ASTPtr arrayJoin() const { return element.array_join; }
|
||||||
@ -329,8 +333,8 @@ void CrossToInnerJoinMatcher::visit(ASTSelectQuery & select, ASTPtr &, Data & da
|
|||||||
{
|
{
|
||||||
if (visitor_data.matchAny(i))
|
if (visitor_data.matchAny(i))
|
||||||
{
|
{
|
||||||
joined_tables[i].rewriteCrossToInner(visitor_data.makeOnExpression(i));
|
if (joined_tables[i].rewriteCrossToInner(visitor_data.makeOnExpression(i)))
|
||||||
data.done = true;
|
data.done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
0 0 0
|
||||||
|
0 0 1
|
||||||
|
0 0 2
|
||||||
|
0 0 3
|
||||||
|
1 1 0
|
||||||
|
1 1 1
|
||||||
|
1 1 2
|
||||||
|
1 1 3
|
||||||
|
-
|
||||||
|
0 0 0
|
||||||
|
0 1 0
|
||||||
|
1 0 1
|
||||||
|
1 1 1
|
||||||
|
2 0 \N
|
||||||
|
2 1 \N
|
||||||
|
-
|
||||||
|
0 0 0
|
||||||
|
0 1 1
|
||||||
|
0 2 2
|
||||||
|
1 0 0
|
||||||
|
1 1 1
|
||||||
|
1 2 2
|
||||||
|
\N \N 3
|
@ -0,0 +1,20 @@
|
|||||||
|
SET join_use_nulls = 1;
|
||||||
|
|
||||||
|
SELECT *
|
||||||
|
FROM numbers(2) AS n1
|
||||||
|
JOIN numbers(3) AS n2 ON n1.number = n2.number, numbers(4) AS n3
|
||||||
|
ORDER BY n1.number, n2.number, n3.number;
|
||||||
|
|
||||||
|
SELECT '-';
|
||||||
|
|
||||||
|
SELECT *
|
||||||
|
FROM numbers(3) AS n1, numbers(2) AS n2
|
||||||
|
LEFT JOIN numbers(2) AS n3 ON n1.number = n3.number
|
||||||
|
ORDER BY n1.number, n2.number, n3.number;
|
||||||
|
|
||||||
|
SELECT '-';
|
||||||
|
|
||||||
|
SELECT *
|
||||||
|
FROM numbers(2) AS n1, numbers(3) AS n2
|
||||||
|
RIGHT JOIN numbers(4) AS n3 ON n2.number = n3.number
|
||||||
|
ORDER BY n1.number, n2.number, n3.number;
|
Loading…
Reference in New Issue
Block a user