fix COMMA and other JOIN mix (#10311)

This commit is contained in:
Artem Zuikov 2020-04-16 23:28:23 +03:00 committed by GitHub
parent d5b3b2c7b6
commit c62c288e4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 4 deletions

View File

@ -52,17 +52,21 @@ struct JoinedElement
void rewriteCommaToCross()
{
if (join)
if (join && join->kind == ASTTableJoin::Kind::Comma)
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->strictness = ASTTableJoin::Strictness::All;
join->on_expression = on_expression;
join->children.push_back(join->on_expression);
return true;
}
ASTPtr arrayJoin() const { return element.array_join; }
@ -329,7 +333,7 @@ void CrossToInnerJoinMatcher::visit(ASTSelectQuery & select, ASTPtr &, Data & da
{
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;
}
}

View File

@ -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

View File

@ -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;