dbms: Server: Performance improvement. [#METR-16778]

This commit is contained in:
Alexey Arno 2015-07-11 18:16:59 +03:00
parent b4f65a44e9
commit 135cac6d77
3 changed files with 22 additions and 10 deletions

View File

@ -36,11 +36,14 @@ public:
ASTPtr clone() const override;
/// Получить глубокую копию дерева первого запроса SELECT.
ASTPtr cloneFirstSelect() const;
/// Возвращает указатель на формат из последнего SELECT'а цепочки UNION ALL.
const IAST * getFormat() const override;
private:
ASTPtr cloneImpl() const;
ASTPtr cloneImpl(bool traverse_union_all) const;
public:
bool distinct = false;

View File

@ -720,10 +720,7 @@ QueryProcessingStage::Enum InterpreterSelectQuery::executeFetchColumns(BlockInpu
if (storage->isRemote())
{
/// В случае удаленного запроса отправляем только SELECT, который выполнится.
actual_query_ptr = query_ptr->clone();
auto actual_select_query = static_cast<ASTSelectQuery *>(&*actual_query_ptr);
actual_select_query->prev_union_all = nullptr;
actual_select_query->next_union_all = nullptr;
actual_query_ptr = query.cloneFirstSelect();
}
else
actual_query_ptr = query_ptr;

View File

@ -134,7 +134,7 @@ void ASTSelectQuery::rewriteSelectExpressionList(const Names & column_names)
ASTPtr ASTSelectQuery::clone() const
{
ASTPtr ptr = cloneImpl();
ASTPtr ptr = cloneImpl(true);
/// Установить указатели на предыдущие запросы SELECT.
ASTPtr current = ptr;
@ -150,7 +150,14 @@ ASTPtr ASTSelectQuery::clone() const
return ptr;
}
ASTPtr ASTSelectQuery::cloneImpl() const
ASTPtr ASTSelectQuery::cloneFirstSelect() const
{
ASTPtr res = cloneImpl(false);
static_cast<ASTSelectQuery *>(&*res)->prev_union_all = nullptr;
return res;
}
ASTPtr ASTSelectQuery::cloneImpl(bool traverse_union_all) const
{
ASTSelectQuery * res = new ASTSelectQuery(*this);
ASTPtr ptr{res};
@ -187,11 +194,16 @@ ASTPtr ASTSelectQuery::cloneImpl() const
#undef CLONE
if (next_union_all)
if (traverse_union_all)
{
res->next_union_all = static_cast<const ASTSelectQuery *>(&*next_union_all)->cloneImpl();
res->children.push_back(res->next_union_all);
if (next_union_all)
{
res->next_union_all = static_cast<const ASTSelectQuery *>(&*next_union_all)->cloneImpl(true);
res->children.push_back(res->next_union_all);
}
}
else
res->next_union_all = nullptr;
return ptr;
}