diff --git a/pkg/frontend/computation_wrapper.go b/pkg/frontend/computation_wrapper.go index 03213c9a5afd..5082792b339a 100644 --- a/pkg/frontend/computation_wrapper.go +++ b/pkg/frontend/computation_wrapper.go @@ -129,6 +129,7 @@ func (cwft *TxnComputationWrapper) Plan() *plan.Plan { func (cwft *TxnComputationWrapper) ResetPlanAndStmt(stmt tree.Statement) { cwft.plan = nil + cwft.freeStmt() cwft.stmt = stmt } @@ -137,13 +138,17 @@ func (cwft *TxnComputationWrapper) GetAst() tree.Statement { } func (cwft *TxnComputationWrapper) Free() { + cwft.freeStmt() + cwft.Clear() +} + +func (cwft *TxnComputationWrapper) freeStmt() { if cwft.stmt != nil { if !cwft.ifIsExeccute { cwft.stmt.Free() cwft.stmt = nil } } - cwft.Clear() } func (cwft *TxnComputationWrapper) Clear() { diff --git a/pkg/frontend/mysql_cmd_executor.go b/pkg/frontend/mysql_cmd_executor.go index 43204fac4d11..179f5bdb44cb 100644 --- a/pkg/frontend/mysql_cmd_executor.go +++ b/pkg/frontend/mysql_cmd_executor.go @@ -2809,6 +2809,9 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error) canCache := true Cached := false defer func() { + execCtx.stmt = nil + execCtx.cw = nil + execCtx.cws = nil if !Cached { for i := 0; i < len(cws); i++ { cws[i].Free()