Added a fix from Vadim Plakhtinskiy @VadimPlh

This commit is contained in:
Alexey Milovidov 2020-04-22 07:32:05 +03:00
parent eb0a1ec755
commit e6acb35d95
3 changed files with 19 additions and 2 deletions

View File

@ -687,8 +687,8 @@ static std::pair<UInt64, UInt64> getLimitLengthAndOffset(const ASTSelectQuery &
static UInt64 getLimitForSorting(const ASTSelectQuery & query, const Context & context) static UInt64 getLimitForSorting(const ASTSelectQuery & query, const Context & context)
{ {
/// Partial sort can be done if there is LIMIT but no DISTINCT or LIMIT BY. /// Partial sort can be done if there is LIMIT but no DISTINCT or LIMIT BY, neither ARRAY JOIN.
if (!query.distinct && !query.limitBy() && !query.limit_with_ties) if (!query.distinct && !query.limitBy() && !query.limit_with_ties && !query.arrayJoinExpressionList())
{ {
auto [limit_length, limit_offset] = getLimitLengthAndOffset(query, context); auto [limit_length, limit_offset] = getLimitLengthAndOffset(query, context);
return limit_length + limit_offset; return limit_length + limit_offset;

View File

@ -0,0 +1,8 @@
['']
['']
[]
[]
['']
['']

View File

@ -0,0 +1,9 @@
SELECT `ParsedParams.Key2` AS x
FROM test.hits
ARRAY JOIN ParsedParams AS PP
ORDER BY x ASC
LIMIT 2;
SELECT arrayJoin(`ParsedParams.Key2`) AS x FROM test.hits ORDER BY x ASC LIMIT 2;
WITH arrayJoin(`ParsedParams.Key2`) AS pp SELECT ParsedParams.Key2 AS x FROM test.hits ORDER BY x ASC LIMIT 2;
WITH arrayJoin(`ParsedParams.Key2`) AS pp SELECT ParsedParams.Key2 AS x FROM test.hits WHERE NOT ignore(pp) ORDER BY x ASC LIMIT 2;