From 1b388085f8eba264f5d2fecd272b6082625e4cb1 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 18 Apr 2024 19:21:07 +0800 Subject: [PATCH] executor: remove the retry for analyze (#52634) (#52662) close pingcap/tidb#52601 --- pkg/executor/analyze_col.go | 2 +- pkg/executor/analyze_col_v2.go | 43 ---------------------------------- 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/pkg/executor/analyze_col.go b/pkg/executor/analyze_col.go index 989339daa4233..2ba5272041ac7 100644 --- a/pkg/executor/analyze_col.go +++ b/pkg/executor/analyze_col.go @@ -64,7 +64,7 @@ type AnalyzeColumnsExec struct { func analyzeColumnsPushDownEntry(gp *gp.Pool, e *AnalyzeColumnsExec) *statistics.AnalyzeResults { if e.AnalyzeInfo.StatsVersion >= statistics.Version2 { - return e.toV2().analyzeColumnsPushDownWithRetryV2(gp) + return e.toV2().analyzeColumnsPushDownV2(gp) } return e.toV1().analyzeColumnsPushDownV1() } diff --git a/pkg/executor/analyze_col_v2.go b/pkg/executor/analyze_col_v2.go index 32032f8da1b27..eeba3f89bdd22 100644 --- a/pkg/executor/analyze_col_v2.go +++ b/pkg/executor/analyze_col_v2.go @@ -17,13 +17,11 @@ package executor import ( "context" stderrors "errors" - "math" "slices" "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" @@ -54,47 +52,6 @@ type AnalyzeColumnsExecV2 struct { *AnalyzeColumnsExec } -func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownWithRetryV2(gp *gp.Pool) *statistics.AnalyzeResults { - analyzeResult := e.analyzeColumnsPushDownV2(gp) - 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(gp) -} - -// 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(gp *gp.Pool) *statistics.AnalyzeResults { var ranges []*ranger.Range if hc := e.handleCols; hc != nil {