From 6403ed2462f2ade2ae58c988d5cecc3c48d0ae81 Mon Sep 17 00:00:00 2001 From: fzhedu Date: Tue, 31 Mar 2020 15:36:43 +0800 Subject: [PATCH 1/2] avoid soring multiple times with unstable order --- store/mockstore/mocktikv/executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/mockstore/mocktikv/executor.go b/store/mockstore/mocktikv/executor.go index 5668707c644d9..c812d435fbaa6 100644 --- a/store/mockstore/mocktikv/executor.go +++ b/store/mockstore/mocktikv/executor.go @@ -567,6 +567,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 } } @@ -575,7 +576,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++ From 48be7246ab61e62fb4e22bb7375d9eae256eb99e Mon Sep 17 00:00:00 2001 From: fzhedu Date: Wed, 8 Apr 2020 13:53:38 +0800 Subject: [PATCH 2/2] add test --- executor/executor_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/executor/executor_test.go b/executor/executor_test.go index bb97f1770acab..67168cf725b66 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -5378,3 +5378,15 @@ func (s *testSuite1) TestIssue15718(c *C) { tk.MustExec("insert into tt values(0, '2', null), (7, null, '1122'), (NULL, 'w', null), (NULL, '2', '3344'), (NULL, NULL, '0'), (7, 'f', '33');") tk.MustQuery("select a and b as d, a or c as e from tt;").Check(testkit.Rows("0 ", " 1", "0 ", " 1", " ", "0 1")) } + +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")) +}