From 533521ff559bd7afd5f6140dfb1e1ec38973a5ab Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 16 Apr 2024 19:12:06 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #52634 Signed-off-by: ti-chi-bot --- executor/analyze_col.go | 4 ++++ executor/analyze_col_v2.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/executor/analyze_col.go b/executor/analyze_col.go index a846816b18428..6727ca5225c65 100644 --- a/executor/analyze_col.go +++ b/executor/analyze_col.go @@ -65,7 +65,11 @@ type AnalyzeColumnsExec struct { func analyzeColumnsPushDownEntry(e *AnalyzeColumnsExec) *statistics.AnalyzeResults { if e.AnalyzeInfo.StatsVersion >= statistics.Version2 { +<<<<<<< HEAD:executor/analyze_col.go return e.toV2().analyzeColumnsPushDownWithRetryV2() +======= + return e.toV2().analyzeColumnsPushDownV2(gp) +>>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col.go } return e.toV1().analyzeColumnsPushDownV1() } diff --git a/executor/analyze_col_v2.go b/executor/analyze_col_v2.go index 7d68cbffa094a..71bc4652918a0 100644 --- a/executor/analyze_col_v2.go +++ b/executor/analyze_col_v2.go @@ -16,13 +16,19 @@ package executor import ( "context" +<<<<<<< HEAD:executor/analyze_col_v2.go "math" "sort" "sync/atomic" +======= + stderrors "errors" + "slices" +>>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col_v2.go "time" "github.com/pingcap/errors" "github.com/pingcap/failpoint" +<<<<<<< HEAD:executor/analyze_col_v2.go "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" @@ -43,6 +49,27 @@ import ( "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tidb/util/timeutil" +======= + "github.com/pingcap/tidb/pkg/domain" + "github.com/pingcap/tidb/pkg/expression" + "github.com/pingcap/tidb/pkg/metrics" + "github.com/pingcap/tidb/pkg/parser/ast" + "github.com/pingcap/tidb/pkg/parser/model" + "github.com/pingcap/tidb/pkg/parser/mysql" + "github.com/pingcap/tidb/pkg/sessionctx" + "github.com/pingcap/tidb/pkg/statistics" + "github.com/pingcap/tidb/pkg/table" + "github.com/pingcap/tidb/pkg/tablecodec" + "github.com/pingcap/tidb/pkg/types" + "github.com/pingcap/tidb/pkg/util" + "github.com/pingcap/tidb/pkg/util/chunk" + "github.com/pingcap/tidb/pkg/util/codec" + "github.com/pingcap/tidb/pkg/util/collate" + "github.com/pingcap/tidb/pkg/util/logutil" + "github.com/pingcap/tidb/pkg/util/memory" + "github.com/pingcap/tidb/pkg/util/ranger" + "github.com/pingcap/tidb/pkg/util/timeutil" +>>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col_v2.go "github.com/pingcap/tipb/go-tipb" "go.uber.org/zap" ) @@ -52,6 +79,7 @@ type AnalyzeColumnsExecV2 struct { *AnalyzeColumnsExec } +<<<<<<< HEAD:executor/analyze_col_v2.go func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownWithRetryV2() *statistics.AnalyzeResults { analyzeResult := e.analyzeColumnsPushDownV2() // do not retry if succeed / not oom error / not auto-analyze / samplerate not set @@ -87,6 +115,9 @@ func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownWithRetryV2() *statistics.A } func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownV2() *statistics.AnalyzeResults { +======= +func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownV2(gp *gp.Pool) *statistics.AnalyzeResults { +>>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col_v2.go var ranges []*ranger.Range if hc := e.handleCols; hc != nil { if hc.IsInt() { From 9ffbbd625c51bc5639a127c0fdc3ff16519f9140 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 3 Jun 2024 13:39:22 +0800 Subject: [PATCH 2/2] * Signed-off-by: Weizhen Wang --- executor/analyze_col.go | 6 +--- executor/analyze_col_v2.go | 67 -------------------------------------- 2 files changed, 1 insertion(+), 72 deletions(-) diff --git a/executor/analyze_col.go b/executor/analyze_col.go index 6727ca5225c65..5ee799b13450c 100644 --- a/executor/analyze_col.go +++ b/executor/analyze_col.go @@ -65,11 +65,7 @@ type AnalyzeColumnsExec struct { func analyzeColumnsPushDownEntry(e *AnalyzeColumnsExec) *statistics.AnalyzeResults { if e.AnalyzeInfo.StatsVersion >= statistics.Version2 { -<<<<<<< HEAD:executor/analyze_col.go - return e.toV2().analyzeColumnsPushDownWithRetryV2() -======= - return e.toV2().analyzeColumnsPushDownV2(gp) ->>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col.go + return e.toV2().analyzeColumnsPushDownV2() } return e.toV1().analyzeColumnsPushDownV1() } diff --git a/executor/analyze_col_v2.go b/executor/analyze_col_v2.go index 71bc4652918a0..a43be6b2235db 100644 --- a/executor/analyze_col_v2.go +++ b/executor/analyze_col_v2.go @@ -16,20 +16,12 @@ package executor import ( "context" -<<<<<<< HEAD:executor/analyze_col_v2.go - "math" "sort" "sync/atomic" -======= - stderrors "errors" - "slices" ->>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col_v2.go "time" "github.com/pingcap/errors" "github.com/pingcap/failpoint" -<<<<<<< HEAD:executor/analyze_col_v2.go - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/metrics" @@ -49,27 +41,6 @@ import ( "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/ranger" "github.com/pingcap/tidb/util/timeutil" -======= - "github.com/pingcap/tidb/pkg/domain" - "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/metrics" - "github.com/pingcap/tidb/pkg/parser/ast" - "github.com/pingcap/tidb/pkg/parser/model" - "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/sessionctx" - "github.com/pingcap/tidb/pkg/statistics" - "github.com/pingcap/tidb/pkg/table" - "github.com/pingcap/tidb/pkg/tablecodec" - "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util" - "github.com/pingcap/tidb/pkg/util/chunk" - "github.com/pingcap/tidb/pkg/util/codec" - "github.com/pingcap/tidb/pkg/util/collate" - "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/memory" - "github.com/pingcap/tidb/pkg/util/ranger" - "github.com/pingcap/tidb/pkg/util/timeutil" ->>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col_v2.go "github.com/pingcap/tipb/go-tipb" "go.uber.org/zap" ) @@ -79,45 +50,7 @@ type AnalyzeColumnsExecV2 struct { *AnalyzeColumnsExec } -<<<<<<< HEAD:executor/analyze_col_v2.go -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.Count <= 0 { - return analyzeResult - } - newSampleRate := math.Min(1, float64(config.DefRowsForSampleRate)/float64(statsTbl.Count)) - 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 { -======= -func (e *AnalyzeColumnsExecV2) analyzeColumnsPushDownV2(gp *gp.Pool) *statistics.AnalyzeResults { ->>>>>>> 2e1d9e1039c (executor: remove the retry for analyze (#52634)):pkg/executor/analyze_col_v2.go var ranges []*ranger.Range if hc := e.handleCols; hc != nil { if hc.IsInt() {