Disable GROUP BY sharding_key optimization for WITH ROLLUP/CUBE/TOTALS

This commit is contained in:
Azat Khuzhin 2020-04-27 00:56:54 +03:00
parent fa2385b26b
commit 20b4eed9a1
3 changed files with 41 additions and 5 deletions

View File

@ -399,8 +399,17 @@ bool StorageDistributed::canForceGroupByNoMerge(const Context &context, QueryPro
const auto & select = query_ptr->as<ASTSelectQuery &>();
if (select.group_by_with_totals || select.group_by_with_rollup || select.group_by_with_cube)
return false;
// TODO: The following can be optimized too (but with some caveats, will be addressed later):
// - ORDER BY
// - LIMIT BY
// - LIMIT
if (select.orderBy())
return false;
if (select.limitBy() || select.limitLength())
return false;
if (select.distinct)
{
@ -416,11 +425,6 @@ bool StorageDistributed::canForceGroupByNoMerge(const Context &context, QueryPro
reason = "DISTINCT " + backQuote(serializeAST(*select.select(), true));
}
// This can use distributed_group_by_no_merge but in this case limit stage
// should be done later (which is not the case right now).
if (select.limitBy() || select.limitLength())
return false;
const ASTPtr group_by = select.groupBy();
if (!group_by)
{

View File

@ -67,3 +67,24 @@ GROUP BY (Distributed-over-Distributed) distributed_group_by_no_merge
1 1
1 0
1 1
extremes
1 0
1 1
1 0
1 1
1 0
1 1
WITH TOTALS
2 0
2 1
4 0
WITH ROLLUP
2 0
2 1
4 0
WITH CUBE
2 0
2 1
4 0

View File

@ -1,3 +1,5 @@
-- TODO: correct testing with real unique shards
drop table if exists dist_01247;
drop table if exists data_01247;
@ -60,3 +62,12 @@ select 'GROUP BY (Distributed-over-Distributed)';
select count(), * from cluster(test_cluster_two_shards, currentDatabase(), dist_01247) group by number;
select 'GROUP BY (Distributed-over-Distributed) distributed_group_by_no_merge';
select count(), * from cluster(test_cluster_two_shards, currentDatabase(), dist_01247) group by number settings distributed_group_by_no_merge=1;
select 'extremes';
select count(), * from dist_01247 group by number settings extremes=1;
select 'WITH TOTALS';
select count(), * from dist_01247 group by number with totals;
select 'WITH ROLLUP';
select count(), * from dist_01247 group by number with rollup;
select 'WITH CUBE';
select count(), * from dist_01247 group by number with cube;