diff --git a/pkg/executor/analyze.go b/pkg/executor/analyze.go index 1e8802815c370..1e2c7ba007dcf 100644 --- a/pkg/executor/analyze.go +++ b/pkg/executor/analyze.go @@ -399,8 +399,10 @@ func (e *AnalyzeExec) handleResultsError( } if atomic.LoadUint32(&e.Ctx().GetSessionVars().Killed) == 1 { finishJobWithLog(e.Ctx(), results.Job, exeerrors.ErrQueryInterrupted) + results.DestroyAndPutToPool() return errors.Trace(exeerrors.ErrQueryInterrupted) } + results.DestroyAndPutToPool() } // Dump stats to historical storage. for tableID := range tableIDs { diff --git a/pkg/executor/analyze_worker.go b/pkg/executor/analyze_worker.go index 0cace481fc141..75921b9db2c0c 100644 --- a/pkg/executor/analyze_worker.go +++ b/pkg/executor/analyze_worker.go @@ -68,6 +68,7 @@ func (worker *analyzeSaveStatsWorker) run(ctx context.Context, analyzeSnapshot b } else { finishJobWithLog(worker.sctx, results.Job, nil) } + results.DestroyAndPutToPool() if err != nil { return } diff --git a/pkg/statistics/analyze.go b/pkg/statistics/analyze.go index 3abfd9ce989c0..c836ca153520b 100644 --- a/pkg/statistics/analyze.go +++ b/pkg/statistics/analyze.go @@ -69,6 +69,13 @@ type AnalyzeResult struct { IsIndex int } +// DestroyAndPutToPool destroys the result and put it to the pool. +func (a *AnalyzeResult) DestroyAndPutToPool() { + for _, f := range a.Fms { + f.DestroyAndPutToPool() + } +} + // AnalyzeResults represents the analyze results of a task. type AnalyzeResults struct { Err error @@ -100,3 +107,10 @@ type AnalyzeResults struct { // table-level fields, we only need to update the version. ForMVIndex bool } + +// DestroyAndPutToPool destroys the result and put it to the pool. +func (a *AnalyzeResults) DestroyAndPutToPool() { + for _, f := range a.Ars { + f.DestroyAndPutToPool() + } +}