Skip to content

Commit

Permalink
executor: remove the retry for analyze (#52634) (#52661)
Browse files Browse the repository at this point in the history
close #52601
  • Loading branch information
ti-chi-bot authored May 21, 2024
1 parent 8e22991 commit 09acf2a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
2 changes: 1 addition & 1 deletion pkg/executor/analyze_col.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type AnalyzeColumnsExec struct {

func analyzeColumnsPushDownEntry(e *AnalyzeColumnsExec) *statistics.AnalyzeResults {
if e.AnalyzeInfo.StatsVersion >= statistics.Version2 {
return e.toV2().analyzeColumnsPushDownWithRetryV2()
return e.toV2().analyzeColumnsPushDownV2()
}
return e.toV1().analyzeColumnsPushDownV1()
}
Expand Down
43 changes: 0 additions & 43 deletions pkg/executor/analyze_col_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ package executor
import (
"context"
stderrors "errors"
"math"
"sort"
"sync/atomic"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/metrics"
Expand Down Expand Up @@ -55,47 +53,6 @@ type AnalyzeColumnsExecV2 struct {
*AnalyzeColumnsExec
}

func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownWithRetryV2() *statistics.AnalyzeResults {
analyzeResult := e.analyzeColumnsPushDownV2()
if e.notRetryable(analyzeResult) {
return analyzeResult
}

finishJobWithLog(e.ctx, analyzeResult.Job, analyzeResult.Err)
statsHandle := domain.GetDomain(e.ctx).StatsHandle()
if statsHandle == nil {
return analyzeResult
}

var statsTbl *statistics.Table
tid := e.tableID.GetStatisticsID()
if tid == e.tableInfo.ID {
statsTbl = statsHandle.GetTableStats(e.tableInfo)
} else {
statsTbl = statsHandle.GetPartitionStats(e.tableInfo, tid)
}
if statsTbl == nil || statsTbl.RealtimeCount <= 0 {
return analyzeResult
}

newSampleRate := math.Min(1, float64(config.DefRowsForSampleRate)/float64(statsTbl.RealtimeCount))
if newSampleRate >= *e.analyzePB.ColReq.SampleRate {
return analyzeResult
}
*e.analyzePB.ColReq.SampleRate = newSampleRate
prepareV2AnalyzeJobInfo(e.AnalyzeColumnsExec, true)
AddNewAnalyzeJob(e.ctx, e.job)
StartAnalyzeJob(e.ctx, e.job)
return e.analyzeColumnsPushDownV2()
}

// Do **not** retry if succeed / not oom error / not auto-analyze / samplerate not set.
func (e *AnalyzeColumnsExecV2) notRetryable(analyzeResult *statistics.AnalyzeResults) bool {
return analyzeResult.Err == nil || analyzeResult.Err != errAnalyzeOOM ||
!e.ctx.GetSessionVars().InRestrictedSQL ||
e.analyzePB.ColReq == nil || *e.analyzePB.ColReq.SampleRate <= 0
}

func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownV2() *statistics.AnalyzeResults {
var ranges []*ranger.Range
if hc := e.handleCols; hc != nil {
Expand Down

0 comments on commit 09acf2a

Please sign in to comment.