Skip to content

Commit 52794d9

Browse files
authored
executor: use analyze scan concurrency to control index analyze (#50639) (#50642)
close #50641
1 parent 9b7ba9b commit 52794d9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

pkg/executor/analyze_col_v2.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,18 @@ func (e *AnalyzeColumnsExecV2) buildSubIndexJobForSpecialIndex(indexInfos []*mod
571571
_, offset := timeutil.Zone(e.ctx.GetSessionVars().Location())
572572
tasks := make([]*analyzeTask, 0, len(indexInfos))
573573
sc := e.ctx.GetSessionVars().StmtCtx
574+
var concurrency int
575+
if e.ctx.GetSessionVars().InRestrictedSQL {
576+
// In restricted SQL, we use the default value of IndexSerialScanConcurrency. it is copied from tidb_sysproc_scan_concurrency.
577+
concurrency = e.ctx.GetSessionVars().IndexSerialScanConcurrency()
578+
} else {
579+
concurrency = e.ctx.GetSessionVars().AnalyzeDistSQLScanConcurrency()
580+
}
574581
for _, indexInfo := range indexInfos {
575582
base := baseAnalyzeExec{
576583
ctx: e.ctx,
577584
tableID: e.TableID,
578-
concurrency: e.ctx.GetSessionVars().IndexSerialScanConcurrency(),
585+
concurrency: concurrency,
579586
analyzePB: &tipb.AnalyzeReq{
580587
Tp: tipb.AnalyzeType_TypeIndex,
581588
Flags: sc.PushDownFlags(),

pkg/executor/builder.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,11 +2559,17 @@ func (b *executorBuilder) buildAnalyzeIndexPushdown(task plannercore.AnalyzeInde
25592559
failpoint.Inject("injectAnalyzeSnapshot", func(val failpoint.Value) {
25602560
startTS = uint64(val.(int))
25612561
})
2562-
2562+
var concurrency int
2563+
if b.ctx.GetSessionVars().InRestrictedSQL {
2564+
// In restricted SQL, we use the default value of IndexSerialScanConcurrency. it is copied from tidb_sysproc_scan_concurrency.
2565+
concurrency = b.ctx.GetSessionVars().IndexSerialScanConcurrency()
2566+
} else {
2567+
concurrency = b.ctx.GetSessionVars().AnalyzeDistSQLScanConcurrency()
2568+
}
25632569
base := baseAnalyzeExec{
25642570
ctx: b.ctx,
25652571
tableID: task.TableID,
2566-
concurrency: b.ctx.GetSessionVars().IndexSerialScanConcurrency(),
2572+
concurrency: concurrency,
25672573
analyzePB: &tipb.AnalyzeReq{
25682574
Tp: tipb.AnalyzeType_TypeIndex,
25692575
Flags: sc.PushDownFlags(),

0 commit comments

Comments
 (0)