From ad970728f08774f71ddda83fa25272ddbd44b6cb Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Fri, 18 Mar 2022 15:28:30 +0800 Subject: [PATCH] cherry pick #33219 to release-6.0 Signed-off-by: ti-srebot --- executor/distsql.go | 9 +++++---- executor/executor_issue_test.go | 17 +++++++++++++++++ executor/table_reader.go | 7 +++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/executor/distsql.go b/executor/distsql.go index e0a1be70bf57f..25a0c8612c0c2 100644 --- a/executor/distsql.go +++ b/executor/distsql.go @@ -213,14 +213,14 @@ func (e *IndexReaderExecutor) setDummy() { // Close clears all resources hold by current object. func (e *IndexReaderExecutor) Close() (err error) { - if e.dummy { - return nil - } - if e.result != nil { err = e.result.Close() } e.result = nil + e.kvRanges = e.kvRanges[:0] + if e.dummy { + return nil + } e.ctx.StoreQueryFeedback(e.feedback) return err } @@ -704,6 +704,7 @@ func (e *IndexLookUpExecutor) buildTableReader(ctx context.Context, task *lookup // Close implements Exec Close interface. func (e *IndexLookUpExecutor) Close() error { + e.kvRanges = e.kvRanges[:0] if e.dummy { return nil } diff --git a/executor/executor_issue_test.go b/executor/executor_issue_test.go index b66a9dfbcf745..a844a4666734c 100644 --- a/executor/executor_issue_test.go +++ b/executor/executor_issue_test.go @@ -1227,3 +1227,20 @@ func TestIssue33038(t *testing.T) { } } } + +func TestIssue33214(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (col enum('a', 'b', 'c') default null)") + tk.MustExec("insert into t values ('a'), ('b'), ('c'), (null), ('c')") + tk.MustExec("alter table t cache") + for { + tk.MustQuery("select col from t t1 where (select count(*) from t t2 where t2.col = t1.col or t2.col = 'sdf') > 1;").Check(testkit.Rows("c", "c")) + if tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache { + break + } + } +} diff --git a/executor/table_reader.go b/executor/table_reader.go index 3b20bf90c98d2..0e37712efe957 100644 --- a/executor/table_reader.go +++ b/executor/table_reader.go @@ -246,15 +246,14 @@ func (e *TableReaderExecutor) Next(ctx context.Context, req *chunk.Chunk) error // Close implements the Executor Close interface. func (e *TableReaderExecutor) Close() error { - if e.dummy { - return nil - } - var err error if e.resultHandler != nil { err = e.resultHandler.Close() } e.kvRanges = e.kvRanges[:0] + if e.dummy { + return nil + } e.ctx.StoreQueryFeedback(e.feedback) return err }