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: reuse the memory from analyze result #47617

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}