fix 'LIMIT WITH TIES' with aliases

This commit is contained in:
Anton Popov 2020-06-16 01:24:00 +03:00
parent d6e69211b1
commit eabbabed04
3 changed files with 45 additions and 0 deletions

View File

@ -973,6 +973,14 @@ void InterpreterSelectQuery::executeImpl(QueryPipeline & pipeline, const BlockIn
executeWithFill(pipeline); 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. /** We must do projection after DISTINCT because projection may remove some columns.
*/ */
executeProjection(pipeline, expressions.final_projection); 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;