Skip to content

Commit

Permalink
mocktikv: avoid sorting multiple times with unstable order (pingcap#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 9, 2020
1 parent 5ca3fde commit 2ade419
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4376,3 +4376,15 @@ func (s *testSuite1) TestPartitionHashCode(c *C) {
}
wg.Wait()
}

func (s *testSuite1) TestIssue15767(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists tt;")
tk.MustExec("create table t(a int, b char);")
tk.MustExec("insert into t values (1,'s'),(2,'b'),(1,'c'),(2,'e'),(1,'a');")
tk.MustExec("insert into t select * from t;")
tk.MustExec("insert into t select * from t;")
tk.MustExec("insert into t select * from t;")
tk.MustQuery("select b, count(*) from ( select b from t order by a limit 20 offset 2) as s group by b order by b;").Check(testkit.Rows("a 6", "c 7", "s 7"))
}
2 changes: 1 addition & 1 deletion store/mockstore/mocktikv/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ func (e *topNExec) Next(ctx context.Context) (value [][]byte, err error) {
return nil, errors.Trace(err)
}
if !hasMore {
sort.Sort(&e.heap.topNSorter)
break
}
}
Expand All @@ -570,7 +571,6 @@ func (e *topNExec) Next(ctx context.Context) (value [][]byte, err error) {
if e.cursor >= len(e.heap.rows) {
return nil, nil
}
sort.Sort(&e.heap.topNSorter)
row := e.heap.rows[e.cursor]
e.cursor++

Expand Down

0 comments on commit 2ade419

Please sign in to comment.