Merge pull request #28975 from ClickHouse/check-what-if-do-not-add-const-agg-keys-with-having

Don not add const group by key for query with only having.
This commit is contained in:
Anton Popov 2021-09-16 18:33:53 +03:00 committed by GitHub
commit 77a995381b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -91,12 +91,7 @@ void optimizeGroupBy(ASTSelectQuery * select_query, const NameSet & source_colum
const FunctionFactory & function_factory = FunctionFactory::instance();
if (!select_query->groupBy())
{
// If there is a HAVING clause without GROUP BY, make sure we have some aggregation happen.
if (select_query->having())
appendUnusedGroupByColumn(select_query, source_columns);
return;
}
const auto is_literal = [] (const ASTPtr & ast) -> bool
{

View File

@ -0,0 +1,5 @@
0
0
0
0
\N

View File

@ -0,0 +1,10 @@
SELECT count() AS cnt WHERE 0 HAVING cnt = 0;
select cnt from (select count() cnt where 0) where cnt = 0;
select cnt from (select count() cnt from system.one where 0) where cnt = 0;
select sum from (select sum(dummy) sum from system.one where 0) where sum = 0;
set aggregate_functions_null_for_empty=1;
select sum from (select sum(dummy) sum from system.one where 0) where sum is null;