Skip to content

Commit

Permalink
executor: use analyze scan concurrency to control index analyze (#50639
Browse files Browse the repository at this point in the history
…) (#50642)

close #50641
  • Loading branch information
ti-chi-bot committed Jan 22, 2024
1 parent 9b7ba9b commit 52794d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/executor/analyze_col_v2.go
Expand Up @@ -571,11 +571,18 @@ func (e *AnalyzeColumnsExecV2) buildSubIndexJobForSpecialIndex(indexInfos []*mod
_, offset := timeutil.Zone(e.ctx.GetSessionVars().Location())
tasks := make([]*analyzeTask, 0, len(indexInfos))
sc := e.ctx.GetSessionVars().StmtCtx
var concurrency int
if e.ctx.GetSessionVars().InRestrictedSQL {
// In restricted SQL, we use the default value of IndexSerialScanConcurrency. it is copied from tidb_sysproc_scan_concurrency.
concurrency = e.ctx.GetSessionVars().IndexSerialScanConcurrency()
} else {
concurrency = e.ctx.GetSessionVars().AnalyzeDistSQLScanConcurrency()
}
for _, indexInfo := range indexInfos {
base := baseAnalyzeExec{
ctx: e.ctx,
tableID: e.TableID,
concurrency: e.ctx.GetSessionVars().IndexSerialScanConcurrency(),
concurrency: concurrency,
analyzePB: &tipb.AnalyzeReq{
Tp: tipb.AnalyzeType_TypeIndex,
Flags: sc.PushDownFlags(),
Expand Down
10 changes: 8 additions & 2 deletions pkg/executor/builder.go
Expand Up @@ -2559,11 +2559,17 @@ func (b *executorBuilder) buildAnalyzeIndexPushdown(task plannercore.AnalyzeInde
failpoint.Inject("injectAnalyzeSnapshot", func(val failpoint.Value) {
startTS = uint64(val.(int))
})

var concurrency int
if b.ctx.GetSessionVars().InRestrictedSQL {
// In restricted SQL, we use the default value of IndexSerialScanConcurrency. it is copied from tidb_sysproc_scan_concurrency.
concurrency = b.ctx.GetSessionVars().IndexSerialScanConcurrency()
} else {
concurrency = b.ctx.GetSessionVars().AnalyzeDistSQLScanConcurrency()
}
base := baseAnalyzeExec{
ctx: b.ctx,
tableID: task.TableID,
concurrency: b.ctx.GetSessionVars().IndexSerialScanConcurrency(),
concurrency: concurrency,
analyzePB: &tipb.AnalyzeReq{
Tp: tipb.AnalyzeType_TypeIndex,
Flags: sc.PushDownFlags(),
Expand Down

0 comments on commit 52794d9

Please sign in to comment.