Skip to content

Commit

Permalink
executor: reuse the memory from analyze result (#47617)
Browse files Browse the repository at this point in the history
ref #47275
  • Loading branch information
hawkingrei committed Oct 13, 2023
1 parent e146d4d commit 8f532ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/executor/analyze_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/statistics/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}

0 comments on commit 8f532ef

Please sign in to comment.