diff --git a/pkg/executor/analyze_col_v2.go b/pkg/executor/analyze_col_v2.go index c734a9be9c32f..1fb3a3834c704 100644 --- a/pkg/executor/analyze_col_v2.go +++ b/pkg/executor/analyze_col_v2.go @@ -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(), diff --git a/pkg/executor/builder.go b/pkg/executor/builder.go index 32dfcc49da78b..2fc032bcd2c55 100644 --- a/pkg/executor/builder.go +++ b/pkg/executor/builder.go @@ -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(),