Skip to content

Commit 82b27ab

Browse files
Merge pull request #11689 from CurtizJ/fix-with-ties
Fix 'LIMIT WITH TIES' with aliases
2 parents ceb8775 + eabbabe commit 82b27ab

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/Interpreters/InterpreterSelectQuery.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,14 @@ void InterpreterSelectQuery::executeImpl(QueryPipeline & pipeline, const BlockIn
973973

974974
executeWithFill(pipeline);
975975

976+
/// If we have 'WITH TIES', we need execute limit before projection,
977+
/// because in that case columns from 'ORDER BY' are used.
978+
if (query.limit_with_ties)
979+
{
980+
executeLimit(pipeline);
981+
has_prelimit = true;
982+
}
983+
976984
/** We must do projection after DISTINCT because projection may remove some columns.
977985
*/
978986
executeProjection(pipeline, expressions.final_projection);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
0 0
2+
1 0
3+
2 0
4+
3 0
5+
4 0
6+
1
7+
1
8+
1
9+
1
10+
1
11+
0
12+
1
13+
2
14+
3
15+
4
16+
0 0
17+
0 1
18+
0 2
19+
0 3
20+
0 4
21+
0 0
22+
0 1
23+
0 2
24+
0 3
25+
0 4
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
select number, intDiv(number,5) value from numbers(20) order by value limit 3 with ties;
2+
3+
drop table if exists wt;
4+
create table wt (a Int, b Int) engine = Memory;
5+
insert into wt select 0, number from numbers(5);
6+
7+
select 1 from wt order by a limit 3 with ties;
8+
select b from wt order by a limit 3 with ties;
9+
with a * 2 as c select a, b from wt order by c limit 3 with ties;
10+
select a * 2 as c, b from wt order by c limit 3 with ties;
11+
12+
drop table if exists wt;

0 commit comments

Comments
 (0)