Merge pull request #36033 from vdimir/cross-join-empty-list

This commit is contained in:
Vladimir C 2022-04-08 11:59:21 +02:00 committed by GitHub
commit 265fa90689
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 4 deletions

View File

@ -182,7 +182,6 @@ struct RewriteTablesVisitorData
} }
}; };
template <size_t version = 1>
bool needRewrite(ASTSelectQuery & select, std::vector<const ASTTableExpression *> & table_expressions) bool needRewrite(ASTSelectQuery & select, std::vector<const ASTTableExpression *> & table_expressions)
{ {
if (!select.tables()) if (!select.tables())
@ -233,8 +232,6 @@ bool needRewrite(ASTSelectQuery & select, std::vector<const ASTTableExpression *
return false; return false;
/// it's not trivial to support mix of JOIN ON & JOIN USING cause of short names /// it's not trivial to support mix of JOIN ON & JOIN USING cause of short names
if (num_using && version <= 1)
throw Exception("Multiple JOIN does not support USING", ErrorCodes::NOT_IMPLEMENTED);
if (num_array_join) if (num_array_join)
throw Exception("Multiple JOIN does not support mix with ARRAY JOINs", ErrorCodes::NOT_IMPLEMENTED); throw Exception("Multiple JOIN does not support mix with ARRAY JOINs", ErrorCodes::NOT_IMPLEMENTED);
return true; return true;
@ -380,7 +377,11 @@ private:
static void visit(ASTSelectQuery & select, ASTPtr &, Data & data) static void visit(ASTSelectQuery & select, ASTPtr &, Data & data)
{ {
if (!data.done) if (!data.done)
{
if (data.expression_list->children.empty())
data.expression_list->children.emplace_back(std::make_shared<ASTAsterisk>());
select.setExpression(ASTSelectQuery::Expression::SELECT, std::move(data.expression_list)); select.setExpression(ASTSelectQuery::Expression::SELECT, std::move(data.expression_list));
}
data.done = true; data.done = true;
} }
}; };
@ -605,7 +606,7 @@ void JoinToSubqueryTransformMatcher::visit(ASTPtr & ast, Data & data)
void JoinToSubqueryTransformMatcher::visit(ASTSelectQuery & select, ASTPtr & ast, Data & data) void JoinToSubqueryTransformMatcher::visit(ASTSelectQuery & select, ASTPtr & ast, Data & data)
{ {
std::vector<const ASTTableExpression *> table_expressions; std::vector<const ASTTableExpression *> table_expressions;
if (!needRewrite<2>(select, table_expressions)) if (!needRewrite(select, table_expressions))
return; return;
auto & src_tables = select.tables()->children; auto & src_tables = select.tables()->children;

View File

@ -0,0 +1,52 @@
24
24
24
24 24 24
0 0 0
0 0 1
0 0 2
0 0 3
0 1 0
0 1 1
0 1 2
0 1 3
0 2 0
0 2 1
0 2 2
0 2 3
1 0 0
1 0 1
1 0 2
1 0 3
1 1 0
1 1 1
1 1 2
1 1 3
1 2 0
1 2 1
1 2 2
1 2 3
0 0 0
0 0 1
0 0 2
0 0 3
0 1 0
0 1 1
0 1 2
0 1 3
0 2 0
0 2 1
0 2 2
0 2 3
1 0 0
1 0 1
1 0 2
1 0 3
1 1 0
1 1 1
1 1 2
1 1 3
1 2 0
1 2 1
1 2 2
1 2 3

View File

@ -0,0 +1,6 @@
SELECT count(1) FROM numbers(2) AS n1, numbers(3) AS n2, numbers(4) AS n3;
SELECT count(*) FROM numbers(2) AS n1, numbers(3) AS n2, numbers(4) AS n3;
SELECT count() FROM numbers(2) AS n1, numbers(3) AS n2, numbers(4) AS n3;
SELECT count(n1.number), count(n2.number), count(n3.number) FROM numbers(2) AS n1, numbers(3) AS n2, numbers(4) AS n3;
SELECT * FROM numbers(2) AS n1, numbers(3) AS n2, numbers(4) AS n3 ORDER BY n1.number, n2.number, n3.number;
SELECT n1.number, n2.number, n3.number FROM numbers(2) AS n1, numbers(3) AS n2, numbers(4) AS n3 ORDER BY n1.number, n2.number, n3.number;