mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 13:13:36 +00:00
Minor style fix for CrossToInnerJoinVisitor getTables
This commit is contained in:
parent
5d40471ea3
commit
c33fb80872
@ -145,19 +145,20 @@ ASTPtr makeOnExpression(const std::vector<ASTPtr> & expressions)
|
|||||||
return makeASTFunction(NameAnd::name, std::move(arguments));
|
return makeASTFunction(NameAnd::name, std::move(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getTables(ASTSelectQuery & select, std::vector<JoinedElement> & joined_tables, size_t & num_comma)
|
std::vector<JoinedElement> getTables(const ASTSelectQuery & select)
|
||||||
{
|
{
|
||||||
if (!select.tables())
|
if (!select.tables())
|
||||||
return false;
|
return {};
|
||||||
|
|
||||||
const auto * tables = select.tables()->as<ASTTablesInSelectQuery>();
|
const auto * tables = select.tables()->as<ASTTablesInSelectQuery>();
|
||||||
if (!tables)
|
if (!tables)
|
||||||
return false;
|
return {};
|
||||||
|
|
||||||
size_t num_tables = tables->children.size();
|
size_t num_tables = tables->children.size();
|
||||||
if (num_tables < 2)
|
if (num_tables < 2)
|
||||||
return false;
|
return {};
|
||||||
|
|
||||||
|
std::vector<JoinedElement> joined_tables;
|
||||||
joined_tables.reserve(num_tables);
|
joined_tables.reserve(num_tables);
|
||||||
size_t num_array_join = 0;
|
size_t num_array_join = 0;
|
||||||
size_t num_using = 0;
|
size_t num_using = 0;
|
||||||
@ -191,13 +192,13 @@ bool getTables(ASTSelectQuery & select, std::vector<JoinedElement> & joined_tabl
|
|||||||
if (!join->children.empty())
|
if (!join->children.empty())
|
||||||
throw Exception("Logical error: CROSS JOIN has expressions", ErrorCodes::LOGICAL_ERROR);
|
throw Exception("Logical error: CROSS JOIN has expressions", ErrorCodes::LOGICAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (join->kind == ASTTableJoin::Kind::Comma)
|
|
||||||
++num_comma;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !num_array_join && num_tables - num_using > 1;
|
if (!num_array_join && num_tables - num_using > 1)
|
||||||
|
return joined_tables;
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -216,26 +217,24 @@ void CrossToInnerJoinMatcher::visit(ASTPtr & ast, Data & data)
|
|||||||
|
|
||||||
void CrossToInnerJoinMatcher::visit(ASTSelectQuery & select, ASTPtr &, Data & data)
|
void CrossToInnerJoinMatcher::visit(ASTSelectQuery & select, ASTPtr &, Data & data)
|
||||||
{
|
{
|
||||||
size_t num_comma = 0;
|
std::vector<JoinedElement> joined_tables = getTables(select);
|
||||||
std::vector<JoinedElement> joined_tables;
|
if (joined_tables.empty())
|
||||||
if (!getTables(select, joined_tables, num_comma))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/// Check if joined_tables are consistent with known tables_with_columns
|
/// Check if joined_tables are consistent with known tables_with_columns
|
||||||
{
|
{
|
||||||
if (joined_tables.size() != data.tables_with_columns.size())
|
if (joined_tables.size() != data.tables_with_columns.size())
|
||||||
throw Exception("Logical error: inconsistent number of tables", ErrorCodes::LOGICAL_ERROR);
|
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||||
|
"Logical error: inconsistent number of tables: {} != {}",
|
||||||
|
joined_tables.size(), data.tables_with_columns.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < joined_tables.size(); ++i)
|
for (size_t i = 0; i < joined_tables.size(); ++i)
|
||||||
joined_tables[i].checkTableName(data.tables_with_columns[i].table, data.current_database);
|
joined_tables[i].checkTableName(data.tables_with_columns[i].table, data.current_database);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// COMMA to CROSS
|
/// COMMA to CROSS
|
||||||
if (num_comma)
|
|
||||||
{
|
|
||||||
for (auto & table : joined_tables)
|
for (auto & table : joined_tables)
|
||||||
table.rewriteCommaToCross();
|
table.rewriteCommaToCross();
|
||||||
}
|
|
||||||
|
|
||||||
/// CROSS to INNER
|
/// CROSS to INNER
|
||||||
if (data.cross_to_inner_join_rewrite && select.where())
|
if (data.cross_to_inner_join_rewrite && select.where())
|
||||||
|
Loading…
Reference in New Issue
Block a user