Merge pull request #11689 from CurtizJ/fix-with-ties

Fix 'LIMIT WITH TIES' with aliases
This commit is contained in:
alexey-milovidov 2020-06-16 06:04:27 +03:00 committed by GitHub
commit 82b27ab618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -973,6 +973,14 @@ void InterpreterSelectQuery::executeImpl(QueryPipeline & pipeline, const BlockIn
executeWithFill(pipeline);
/// If we have 'WITH TIES', we need execute limit before projection,
/// because in that case columns from 'ORDER BY' are used.
if (query.limit_with_ties)
{
executeLimit(pipeline);
has_prelimit = true;
}
/** We must do projection after DISTINCT because projection may remove some columns.
*/
executeProjection(pipeline, expressions.final_projection);

View File

@ -0,0 +1,25 @@
0 0
1 0
2 0
3 0
4 0
1
1
1
1
1
0
1
2
3
4
0 0
0 1
0 2
0 3
0 4
0 0
0 1
0 2
0 3
0 4

View File

@ -0,0 +1,12 @@
select number, intDiv(number,5) value from numbers(20) order by value limit 3 with ties;
drop table if exists wt;
create table wt (a Int, b Int) engine = Memory;
insert into wt select 0, number from numbers(5);
select 1 from wt order by a limit 3 with ties;
select b from wt order by a limit 3 with ties;
with a * 2 as c select a, b from wt order by c limit 3 with ties;
select a * 2 as c, b from wt order by c limit 3 with ties;
drop table if exists wt;