mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-21 09:10:48 +00:00
fix
fix
This commit is contained in:
parent
9194985d48
commit
0f9065a91f
@ -282,10 +282,17 @@ BlockIO InterpreterInsertQuery::execute()
|
||||
|
||||
if (settings.optimize_trivial_insert_select)
|
||||
{
|
||||
const auto & selects = query.select->as<ASTSelectWithUnionQuery &>().list_of_selects->children;
|
||||
const auto & select_query = query.select->as<ASTSelectWithUnionQuery &>();
|
||||
const auto & selects = select_query.list_of_selects->children;
|
||||
const auto & union_modes = select_query.list_of_modes;
|
||||
|
||||
/// ASTSelectWithUnionQuery is not normalized now, so it may pass some querys which can be Trivial select querys
|
||||
is_trivial_insert_select
|
||||
= std::all_of(selects.begin(), selects.end(), [](const ASTPtr & select) { return isTrivialSelect(select); });
|
||||
= std::all_of(
|
||||
union_modes.begin(),
|
||||
union_modes.end(),
|
||||
[](const ASTSelectWithUnionQuery::Mode & mode) { return mode == ASTSelectWithUnionQuery::Mode::ALL; })
|
||||
&& std::all_of(selects.begin(), selects.end(), [](const ASTPtr & select) { return isTrivialSelect(select); });
|
||||
}
|
||||
|
||||
if (is_trivial_insert_select)
|
||||
|
@ -122,6 +122,7 @@ struct CustomizeASTSelectWithUnionQueryNormalize
|
||||
}
|
||||
};
|
||||
|
||||
/// We need normalize children first, so we should visit AST tree bottom up
|
||||
using CustomizeASTSelectWithUnionQueryNormalizeVisitor
|
||||
= InDepthNodeVisitor<OneTypeMatcher<CustomizeASTSelectWithUnionQueryNormalize>, false>;
|
||||
|
||||
@ -136,6 +137,14 @@ InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(
|
||||
{
|
||||
CustomizeASTSelectWithUnionQueryNormalizeVisitor::Data union_default_mode{context->getSettingsRef().union_default_mode};
|
||||
CustomizeASTSelectWithUnionQueryNormalizeVisitor(union_default_mode).visit(query_ptr);
|
||||
|
||||
/// After normalization, if it only has one ASTSelectWithUnionQuery child,
|
||||
/// we can lift it up, this can reduce one unnecessary recursion later.
|
||||
if (ast.list_of_selects->children.size() == 1 && ast.list_of_selects->children.at(0)->as<ASTSelectWithUnionQuery>())
|
||||
{
|
||||
query_ptr = std::move(ast.list_of_selects->children.at(0));
|
||||
ast = query_ptr->as<ASTSelectWithUnionQuery &>();
|
||||
}
|
||||
}
|
||||
|
||||
size_t num_children = ast.list_of_selects->children.size();
|
||||
|
Loading…
Reference in New Issue
Block a user