Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: make auto-analyze concurrency configurable #37078

Merged
merged 15 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,20 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
if !ok {
oriIso = "REPEATABLE-READ"
}
terror.Log(sctx.GetSessionVars().SetSystemVar(variable.TiDBBuildStatsConcurrency, "1"))
sctx.GetSessionVars().SetDistSQLScanConcurrency(1)
autoConcurrency, err1 := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(ctx, variable.TiDBAutoBuildStatsConcurrency)
terror.Log(err1)
if err1 == nil {
terror.Log(sctx.GetSessionVars().SetSystemVar(variable.TiDBBuildStatsConcurrency, autoConcurrency))
}
sVal, err2 := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(ctx, variable.TiDBSysProcScanConcurrency)
terror.Log(err2)
if err2 == nil {
concurrency, err3 := strconv.ParseInt(sVal, 10, 64)
terror.Log(err3)
if err3 == nil {
sctx.GetSessionVars().SetDistSQLScanConcurrency(int(concurrency))
}
}
sctx.GetSessionVars().SetIndexSerialScanConcurrency(1)
terror.Log(sctx.GetSessionVars().SetSystemVar(variable.TxnIsolation, ast.ReadCommitted))
defer func() {
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,8 @@ var defaultSysVars = []*SysVar{
}, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
return BoolToOnOff(EnableTmpStorageOnOOM.Load()), nil
}},
{Scope: ScopeGlobal, Name: TiDBAutoBuildStatsConcurrency, Value: strconv.Itoa(DefTiDBAutoBuildStatsConcurrency), Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency},
{Scope: ScopeGlobal, Name: TiDBSysProcScanConcurrency, Value: strconv.Itoa(DefTiDBSysProcScanConcurrency), Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency},
{Scope: ScopeGlobal, Name: TiDBMemoryUsageAlarmRatio, Value: strconv.FormatFloat(DefMemoryUsageAlarmRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0, SetGlobal: func(_ context.Context, s *SessionVars, val string) error {
MemoryUsageAlarmRatio.Store(tidbOptFloat64(val, DefMemoryUsageAlarmRatio))
return nil
Expand Down
6 changes: 6 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,10 @@ const (
TiDBDDLEnableFastReorg = "tidb_ddl_enable_fast_reorg"
// TiDBDDLDiskQuota used to set disk quota for lightning add index.
TiDBDDLDiskQuota = "tidb_ddl_disk_quota"
// TiDBAutoBuildStatsConcurrency is used to set the build concurrency of auto-analyze.
TiDBAutoBuildStatsConcurrency = "tidb_auto_build_stats_concurrency"
// TiDBSysProcScanConcurrency is used to set the scan concurrency of for backend system processes, like auto-analyze.
TiDBSysProcScanConcurrency = "tidb_sysproc_scan_concurrency"
// TiDBServerMemoryLimit indicates the memory limit of the tidb-server instance.
TiDBServerMemoryLimit = "tidb_server_memory_limit"
// TiDBServerMemoryLimitSessMinSize indicates the minimal memory used of a session, that becomes a candidate for session kill.
Expand Down Expand Up @@ -1084,6 +1088,8 @@ const (
MaxDDLReorgBatchSize int32 = 10240
MinDDLReorgBatchSize int32 = 32
MinExpensiveQueryTimeThreshold uint64 = 10 // 10s
DefTiDBAutoBuildStatsConcurrency = 1
DefTiDBSysProcScanConcurrency = 1
DefTiDBRcWriteCheckTs = false
DefTiDBForeignKeyChecks = false
DefTiDBAnalyzePartitionConcurrency = 1
Expand Down