mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-03 13:02:00 +00:00
fix group by with totals/rollup/cube modifers and min/max functions over group by keys
This commit is contained in:
parent
840d96255e
commit
ab4c43cb81
@ -644,8 +644,13 @@ void TreeOptimizer::apply(ASTPtr & query, Aliases & aliases, const NameSet & sou
|
||||
optimizeInjectiveFunctionsInsideUniq(query, context);
|
||||
|
||||
/// Eliminate min/max/any aggregators of functions of GROUP BY keys
|
||||
if (settings.optimize_aggregators_of_group_by_keys)
|
||||
if (settings.optimize_aggregators_of_group_by_keys
|
||||
&& !select_query->group_by_with_totals
|
||||
&& !select_query->group_by_with_rollup
|
||||
&& !select_query->group_by_with_cube)
|
||||
{
|
||||
optimizeAggregateFunctionsOfGroupByKeys(select_query, query);
|
||||
}
|
||||
|
||||
/// Remove duplicate items from ORDER BY.
|
||||
optimizeDuplicatesInOrderBy(select_query);
|
||||
|
@ -0,0 +1,20 @@
|
||||
totals
|
||||
1 1 1
|
||||
2 2 2
|
||||
3 3 3
|
||||
|
||||
0 1 3
|
||||
rollup
|
||||
1 1 1
|
||||
2 2 2
|
||||
3 3 3
|
||||
0 1 3
|
||||
cube
|
||||
1 1 1
|
||||
2 2 2
|
||||
3 3 3
|
||||
0 1 3
|
||||
=======
|
||||
1 1 2 1
|
||||
2 2 3 1
|
||||
0 1 3 2
|
18
tests/queries/0_stateless/01532_min_max_with_modifiers.sql
Normal file
18
tests/queries/0_stateless/01532_min_max_with_modifiers.sql
Normal file
@ -0,0 +1,18 @@
|
||||
SELECT 'totals';
|
||||
SELECT number % 3 + 1 AS n, min(n), max(n) FROM numbers(100) GROUP BY n WITH TOTALS;
|
||||
SELECT 'rollup';
|
||||
SELECT number % 3 + 1 AS n, min(n), max(n) FROM numbers(100) GROUP BY n WITH ROLLUP;
|
||||
SELECT 'cube';
|
||||
SELECT number % 3 + 1 AS n, min(n), max(n) FROM numbers(100) GROUP BY n WITH CUBE;
|
||||
SELECT '=======';
|
||||
|
||||
SELECT
|
||||
x,
|
||||
min(x) AS lower,
|
||||
max(x) + 1 AS upper,
|
||||
upper - lower AS range
|
||||
FROM
|
||||
(
|
||||
SELECT arrayJoin([1, 2]) AS x
|
||||
)
|
||||
GROUP BY x WITH ROLLUP;
|
Loading…
Reference in New Issue
Block a user