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: fix analyze update panic cause by duplicate call analyze executor Close method #20390

Merged
merged 11 commits into from
Oct 12, 2020
14 changes: 7 additions & 7 deletions executor/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (e *ExplainExec) Next(ctx context.Context, req *chunk.Chunk) error {
}

func (e *ExplainExec) generateExplainInfo(ctx context.Context) (rows [][]string, err error) {
closed := false
defer func() {
if !closed && e.analyzeExec != nil {
err = e.analyzeExec.Close()
closed = true
}
}()
if e.analyzeExec != nil && !e.executed {
closed := false
defer func() {
if !closed && e.analyzeExec != nil {
err = e.analyzeExec.Close()
closed = true
}
}()
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
e.executed = true
chk := newFirstChunk(e.analyzeExec)
var nextErr, closeErr error
Expand Down
11 changes: 6 additions & 5 deletions executor/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ func (s *testSuite1) TestExplainWrite(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int)")
tk.MustExec("explain analyze insert into t select 1")
tk.MustQuery("explain analyze insert into t select 1")
tk.MustQuery("select * from t").Check(testkit.Rows("1"))
tk.MustExec("explain analyze update t set a=2 where a=1")
tk.MustQuery("explain analyze update t set a=2 where a=1")
tk.MustQuery("select * from t").Check(testkit.Rows("2"))
tk.MustExec("explain insert into t select 1")
tk.MustQuery("explain insert into t select 1")
tk.MustQuery("select * from t").Check(testkit.Rows("2"))
tk.MustExec("explain analyze insert into t select 1")
tk.MustQuery("select * from t order by a").Check(testkit.Rows("1", "2"))
tk.MustQuery("explain analyze insert into t select 1")
tk.MustQuery("explain analyze replace into t values (3)")
tk.MustQuery("select * from t order by a").Check(testkit.Rows("1", "2", "3"))
}

func (s *testSuite1) TestExplainAnalyzeMemory(c *C) {
Expand Down