Merge pull request #27424 from azat/WithMergeableStateAfterAggregationAndLimit-tests-fixes

Fix tests for WithMergeableStateAfterAggregationAndLimit
This commit is contained in:
alexey-milovidov 2021-08-08 18:14:04 +03:00 committed by GitHub
commit 560e71dcfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 17 deletions

View File

@ -1378,7 +1378,7 @@ void InterpreterSelectQuery::executeImpl(QueryPlan & query_plan, const BlockInpu
/// Limit is no longer needed if there is prelimit. /// Limit is no longer needed if there is prelimit.
/// ///
/// NOTE: that LIMIT cannot be applied of OFFSET should not be applied, /// NOTE: that LIMIT cannot be applied if OFFSET should not be applied,
/// since LIMIT will apply OFFSET too. /// since LIMIT will apply OFFSET too.
/// This is the case for various optimizations for distributed queries, /// This is the case for various optimizations for distributed queries,
/// and when LIMIT cannot be applied it will be applied on the initiator anyway. /// and when LIMIT cannot be applied it will be applied on the initiator anyway.

View File

@ -553,7 +553,6 @@ std::optional<QueryProcessingStage::Enum> StorageDistributed::getOptimizedQueryP
if (const ASTPtr order_by = select.orderBy()) if (const ASTPtr order_by = select.orderBy())
return default_stage; return default_stage;
// LIMIT BY
// LIMIT // LIMIT
// OFFSET // OFFSET
if (select.limitLength() || select.limitOffset()) if (select.limitLength() || select.limitOffset())

View File

@ -1,7 +1,7 @@
-- { echo } -- { echo }
explain select * from remote('127.{1,2}', view(select * from numbers(1e6))) order by number limit 10 settings distributed_push_down_limit=0; explain select * from remote('127.{1,2}', view(select * from numbers(1e6))) order by number limit 10 settings distributed_push_down_limit=0;
Expression (Projection) Expression (Projection)
Limit (preliminary LIMIT) Limit (preliminary LIMIT (without OFFSET))
MergingSorted (Merge sorted streams after aggregation stage for ORDER BY) MergingSorted (Merge sorted streams after aggregation stage for ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
Union Union
@ -16,11 +16,11 @@ Expression (Projection)
ReadFromRemote (Read from remote replica) ReadFromRemote (Read from remote replica)
explain select * from remote('127.{1,2}', view(select * from numbers(1e6))) order by number limit 10 settings distributed_push_down_limit=1; explain select * from remote('127.{1,2}', view(select * from numbers(1e6))) order by number limit 10 settings distributed_push_down_limit=1;
Expression (Projection) Expression (Projection)
Limit (preliminary LIMIT) Limit (preliminary LIMIT (without OFFSET))
MergingSorted (Merge sorted streams after aggregation stage for ORDER BY) MergingSorted (Merge sorted streams after aggregation stage for ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
Union Union
Limit (preliminary LIMIT) Limit (preliminary LIMIT (with OFFSET))
MergingSorted (Merge sorted streams for ORDER BY) MergingSorted (Merge sorted streams for ORDER BY)
MergeSorting (Merge sorted blocks for ORDER BY) MergeSorting (Merge sorted blocks for ORDER BY)
PartialSorting (Sort each block for ORDER BY) PartialSorting (Sort each block for ORDER BY)

View File

@ -1,16 +1,17 @@
-- { echo } -- { echo }
SELECT * SELECT *
FROM remote('127.{1,2}', view( FROM remote('127.{1,2}', view(
SELECT * SELECT number%20 number
FROM numbers(10) FROM numbers(40)
WHERE (number % 2) = (shardNum() - 1)
), number) ), number)
GROUP BY number GROUP BY number
ORDER BY number ASC ORDER BY number ASC
LIMIT 1 BY number LIMIT 1 BY number
LIMIT 5, 5 LIMIT 5, 5
SETTINGS SETTINGS
optimize_skip_unused_shards = 1, optimize_skip_unused_shards=1,
optimize_distributed_group_by_sharding_key = 1, optimize_distributed_group_by_sharding_key=1,
distributed_push_down_limit=1; distributed_push_down_limit=1;
5 5
6 6
@ -19,8 +20,9 @@ SETTINGS
9 9
SELECT * SELECT *
FROM remote('127.{1,2}', view( FROM remote('127.{1,2}', view(
SELECT * SELECT number%20 number
FROM numbers(10) FROM numbers(40)
WHERE (number % 2) = (shardNum() - 1)
), number) ), number)
GROUP BY number GROUP BY number
ORDER BY number ASC ORDER BY number ASC

View File

@ -1,21 +1,31 @@
-- Here we use a trick with shardNum() to generate unique data on each shard.
-- Since distributed_group_by_no_merge=2 will use WithMergeableStateAfterAggregationAndLimit,
-- which assume that the data on shards is unique
-- (LIMIT BY will be applied only on shards, not on the initiator).
-- To distinguish echoing from the comments above we use SELECT FORMAT Null.
SELECT '' FORMAT Null;
-- { echo } -- { echo }
SELECT * SELECT *
FROM remote('127.{1,2}', view( FROM remote('127.{1,2}', view(
SELECT * SELECT number%20 number
FROM numbers(10) FROM numbers(40)
WHERE (number % 2) = (shardNum() - 1)
), number) ), number)
GROUP BY number GROUP BY number
ORDER BY number ASC ORDER BY number ASC
LIMIT 1 BY number LIMIT 1 BY number
LIMIT 5, 5 LIMIT 5, 5
SETTINGS SETTINGS
optimize_skip_unused_shards = 1, optimize_skip_unused_shards=1,
optimize_distributed_group_by_sharding_key = 1, optimize_distributed_group_by_sharding_key=1,
distributed_push_down_limit=1; distributed_push_down_limit=1;
SELECT * SELECT *
FROM remote('127.{1,2}', view( FROM remote('127.{1,2}', view(
SELECT * SELECT number%20 number
FROM numbers(10) FROM numbers(40)
WHERE (number % 2) = (shardNum() - 1)
), number) ), number)
GROUP BY number GROUP BY number
ORDER BY number ASC ORDER BY number ASC