Merge pull request #3340 from CurtizJ/issue-3253

Fix unnecessarily preparations for join at initial server [ISSUE-3253]
This commit is contained in:
alexey-milovidov 2018-10-10 23:04:13 +03:00 committed by GitHub
commit b9ecc4b819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -574,14 +574,20 @@ void ExpressionAnalyzer::initGlobalSubqueries(ASTPtr & ast)
{
/// For GLOBAL IN.
if (do_global && (func->name == "globalIn" || func->name == "globalNotIn"))
{
addExternalStorage(func->arguments->children.at(1));
has_global_subqueries = true;
}
}
else if (ASTTablesInSelectQueryElement * table_elem = typeid_cast<ASTTablesInSelectQueryElement *>(ast.get()))
{
/// For GLOBAL JOIN.
if (do_global && table_elem->table_join
&& static_cast<const ASTTableJoin &>(*table_elem->table_join).locality == ASTTableJoin::Locality::Global)
{
addExternalStorage(table_elem->table_expression);
has_global_subqueries = true;
}
}
}

View File

@ -186,6 +186,8 @@ public:
bool isRewriteSubqueriesPredicate() { return rewrite_subqueries; }
bool hasGlobalSubqueries() { return has_global_subqueries; }
private:
ASTPtr query;
ASTSelectQuery * select_query;
@ -216,6 +218,7 @@ private:
/// Do I need to prepare for execution global subqueries when analyzing the query.
bool do_global;
bool has_global_subqueries = false;
SubqueriesForSets subqueries_for_sets;

View File

@ -549,6 +549,10 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt
if (query.limit_length)
executePreLimit(pipeline);
}
// If there is no global subqueries, we can run subqueries only when recieve them on server.
if (!query_analyzer->hasGlobalSubqueries() && !expressions.subqueries_for_sets.empty())
executeSubqueriesInSetsAndJoins(pipeline, expressions.subqueries_for_sets);
}
if (expressions.second_stage)
@ -654,7 +658,7 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt
}
}
if (!expressions.subqueries_for_sets.empty())
if (query_analyzer->hasGlobalSubqueries() && !expressions.subqueries_for_sets.empty())
executeSubqueriesInSetsAndJoins(pipeline, expressions.subqueries_for_sets);
}