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 4c0624c commit c21ca8f
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 @@ -3990,3 +3990,15 @@ func testGetTableByName(c *C, ctx sessionctx.Context, db, table string) table.Ta
c.Assert(err, IsNil)
return tbl
}

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 @@ -533,6 +533,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 @@ -541,7 +542,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 c21ca8f

Please sign in to comment.