diff --git a/executor/simple_test.go b/executor/simple_test.go index 2fba543b49309..d5c631d5b2458 100644 --- a/executor/simple_test.go +++ b/executor/simple_test.go @@ -57,6 +57,16 @@ func (s *testSuite3) TestDo(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("do 1, @a:=1") tk.MustQuery("select @a").Check(testkit.Rows("1")) + + tk.MustExec("use test") + tk.MustExec("create table t (i int)") + tk.MustExec("insert into t values (1)") + tk2 := testkit.NewTestKit(c, s.store) + tk2.MustExec("use test") + tk.MustQuery("select * from t").Check(testkit.Rows("1")) + tk.MustExec("do @a := (select * from t where i = 1)") + tk2.MustExec("insert into t values (2)") + tk.MustQuery("select * from t").Check(testkit.Rows("1", "2")) } func (s *testSuite3) TestSetRoleAllCorner(c *C) { diff --git a/session/tidb.go b/session/tidb.go index 275f354f1c5f6..bfa883d84e58e 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -325,7 +325,6 @@ func runStmt(ctx context.Context, sctx sessionctx.Context, s sqlexec.Statement) } else { logutil.BgLogger().Error("get txn failed", zap.Error(err1)) } - err = finishStmt(ctx, se, err, s) } if rs != nil { @@ -336,6 +335,7 @@ func runStmt(ctx context.Context, sctx sessionctx.Context, s sqlexec.Statement) }, err } + err = finishStmt(ctx, se, err, s) if se.hasQuerySpecial() { // The special query will be handled later in handleQuerySpecial, // then should call the ExecStmt.FinishExecuteStmt to finish this statement.