Skip to content

Commit

Permalink
executor: remove the retry for analyze (pingcap#52634) (pingcap#52679)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jun 3, 2024
1 parent 769a2f8 commit 409465c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 37 deletions.
2 changes: 1 addition & 1 deletion 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
36 changes: 0 additions & 36 deletions executor/analyze_col_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ package executor

import (
"context"
"math"
"sort"
"sync/atomic"
"time"

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

func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownWithRetryV2() *statistics.AnalyzeResults {
analyzeResult := e.analyzeColumnsPushDownV2()
// do not retry if succeed / not oom error / not auto-analyze / samplerate not set
if analyzeResult.Err == nil || analyzeResult.Err != errAnalyzeOOM ||
!e.ctx.GetSessionVars().InRestrictedSQL ||
e.analyzePB.ColReq == nil || *e.analyzePB.ColReq.SampleRate <= 0 {
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()
}

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

0 comments on commit 409465c

Please sign in to comment.