Fix optimize_distributed_group_by_sharding_key for query with OFFSET only (#16996)

* Fix optimize_distributed_group_by_sharding_key for query with OFFSET only

* Fix 01244_optimize_distributed_group_by_sharding_key flakiness
This commit is contained in:
Azat Khuzhin 2020-12-02 20:11:39 +03:00 committed by GitHub
parent 9b72323594
commit 5365718f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -315,7 +315,8 @@ std::optional<QueryProcessingStage::Enum> getOptimizedQueryProcessingStage(const
// LIMIT BY
// LIMIT
if (select.limitBy() || select.limitLength())
// OFFSET
if (select.limitBy() || select.limitLength() || select.limitOffset())
return QueryProcessingStage::WithMergeableStateAfterAggregation;
// Only simple SELECT FROM GROUP BY sharding_key can use Complete state.

View File

@ -57,6 +57,10 @@ LIMIT
1 0
LIMIT OFFSET
1 1
OFFSET
1 1
1 0
1 1
WHERE LIMIT OFFSET
1 1
LIMIT BY 1

View File

@ -16,6 +16,7 @@ create table dist_01247 as data_01247 engine=Distributed(test_cluster_two_shards
-- (and this is how we ensure that this optimization will work)
set max_distributed_connections=1;
set prefer_localhost_replica=0;
select '-';
select * from dist_01247;
@ -63,6 +64,8 @@ select 'LIMIT';
select count(), * from dist_01247 group by number limit 1;
select 'LIMIT OFFSET';
select count(), * from dist_01247 group by number limit 1 offset 1;
select 'OFFSET';
select count(), * from dist_01247 group by number offset 1;
-- this will emulate different data on for different shards
select 'WHERE LIMIT OFFSET';
select count(), * from dist_01247 where number = _shard_num-1 group by number limit 1 offset 1;