Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: reset all state when table reader executor close (#33219) #33229

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions executor/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions executor/executor_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
7 changes: 3 additions & 4 deletions executor/table_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,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
}
Expand Down