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) #33227

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -198,14 +198,14 @@ type IndexReaderExecutor struct {

// Close clears all resources hold by current object.
func (e *IndexReaderExecutor) Close() (err error) {
if e.table != nil && e.table.Meta().TempTableType != model.TempTableNone {
return nil
}

if e.result != nil {
err = e.result.Close()
}
e.result = nil
e.kvRanges = e.kvRanges[:0]
if e.table != nil && e.table.Meta().TempTableType != model.TempTableNone {
return nil
}
e.ctx.StoreQueryFeedback(e.feedback)
return err
}
Expand Down Expand Up @@ -677,6 +677,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.table.Meta().TempTableType != model.TempTableNone {
return nil
}
Expand Down
7 changes: 3 additions & 4 deletions executor/table_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,14 @@ func fillExtraPIDColumn(req *chunk.Chunk, extraPIDColumnIndex int, physicalID in

// Close implements the Executor Close interface.
func (e *TableReaderExecutor) Close() error {
if e.table.Meta() != nil && e.table.Meta().TempTableType != model.TempTableNone {
return nil
}

var err error
if e.resultHandler != nil {
err = e.resultHandler.Close()
}
e.kvRanges = e.kvRanges[:0]
if e.table.Meta() != nil && e.table.Meta().TempTableType != model.TempTableNone {
return nil
}
e.ctx.StoreQueryFeedback(e.feedback)
return err
}
Expand Down
17 changes: 17 additions & 0 deletions executor/temporary_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,20 @@ func assertTemporaryTableNoNetwork(t *testing.T, createTable func(*testkit.TestK
tk.MustExec("select * from tmp_t where id > 1 for update")
tk.MustExec("rollback")
}

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
}
}
}