Disable trivial_insert_select if query has aggregate functions.

(cherry picked from commit 70ae043455)
This commit is contained in:
Nikolai Kochetov 2020-12-23 17:48:14 +03:00 committed by Alexander Tokmakov
parent b6be194d3a
commit a34411f51e

View File

@ -2,6 +2,7 @@
#include <Access/Common/AccessFlags.h>
#include <Access/EnabledQuota.h>
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <Columns/ColumnNullable.h>
#include <Processors/Transforms/buildPushingToViewsChain.h>
#include <DataTypes/DataTypeNullable.h>
@ -153,7 +154,18 @@ Block InterpreterInsertQuery::getSampleBlock(
return res;
}
static bool hasAggregateFunctions(const IAST * ast)
{
if (const auto * func = typeid_cast<const ASTFunction *>(ast))
if (AggregateFunctionFactory::instance().isAggregateFunctionName(func->name))
return true;
for (const auto & child : ast->children)
if (hasAggregateFunctions(child.get()))
return true;
return false;
}
/** A query that just reads all data without any complex computations or filetering.
* If we just pipe the result to INSERT, we don't have to use too many threads for read.
*/
@ -186,7 +198,8 @@ static bool isTrivialSelect(const ASTPtr & select)
&& !select_query->groupBy()
&& !select_query->having()
&& !select_query->orderBy()
&& !select_query->limitBy());
&& !select_query->limitBy()
&& !hasAggregateFunctions(select_query));
}
/// This query is ASTSelectWithUnionQuery subquery
return false;