From a57827236a70316859996e8be482b6008832d184 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Thu, 27 Aug 2020 12:53:51 +0800 Subject: [PATCH] executor: fix incorrect results when there is an IndexLookUp under the inner side of an Apply (#19496) (#19508) * cherry pick #19496 to release-4.0 Signed-off-by: ti-srebot * fix CI Co-authored-by: Yuanjia Zhang --- executor/distsql.go | 1 + executor/executor_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/executor/distsql.go b/executor/distsql.go index 01c89a176d42a..b7e17b93d09ca 100644 --- a/executor/distsql.go +++ b/executor/distsql.go @@ -557,6 +557,7 @@ func (e *IndexLookUpExecutor) Close() error { e.finished = nil e.workerStarted = false e.memTracker = nil + e.resultCurr = nil return nil } diff --git a/executor/executor_test.go b/executor/executor_test.go index 58f95f08b3e1c..00f6fc523d94a 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -5940,3 +5940,14 @@ func (s *testSplitTable) TestKillTableReader(c *C) { atomic.StoreUint32(&tk.Se.GetSessionVars().Killed, 1) wg.Wait() } + +func (s *testSuite) TestIssue19372(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test;") + tk.MustExec("drop table if exists t1, t2;") + tk.MustExec("create table t1 (c_int int, c_str varchar(40), key(c_str));") + tk.MustExec("create table t2 like t1;") + tk.MustExec("insert into t1 values (1, 'a'), (2, 'b'), (3, 'c');") + tk.MustExec("insert into t2 select * from t1;") + tk.MustQuery("select (select t2.c_str from t2 where t2.c_str <= t1.c_str and t2.c_int in (1, 2) order by t2.c_str limit 1) x from t1 order by c_int;").Check(testkit.Rows("a", "a", "a")) +}