Skip to content

Commit

Permalink
make auto-analyze concurrency configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysan committed Aug 22, 2022
1 parent 3d5577b commit 77d372a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"runtime/trace"
"strconv"
"strings"
"sync/atomic"
"time"
Expand Down Expand Up @@ -425,9 +426,19 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
oriScan := sctx.GetSessionVars().DistSQLScanConcurrency()
oriIndex := sctx.GetSessionVars().IndexSerialScanConcurrency()
oriIso, _ := sctx.GetSessionVars().GetSystemVar(variable.TxnIsolation)
terror.Log(sctx.GetSessionVars().SetSystemVar(variable.TiDBBuildStatsConcurrency, "1"))
sctx.GetSessionVars().SetDistSQLScanConcurrency(1)
sctx.GetSessionVars().SetIndexSerialScanConcurrency(1)
autoConcurrency, err1 := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.TiDBAutoBuildStatsConcurrency)
terror.Log(err1)
if err1 == nil {
terror.Log(sctx.GetSessionVars().SetSystemVar(variable.TiDBBuildStatsConcurrency, autoConcurrency))
}
sVal, err2 := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.TiDBSysProcScanConcurrency)
terror.Log(err2)
if err2 == nil {
concurrency, err3 := strconv.ParseInt(sVal, 10, 64)
terror.Log(err3)
sctx.GetSessionVars().SetDistSQLScanConcurrency(int(concurrency))
sctx.GetSessionVars().SetIndexSerialScanConcurrency(int(concurrency))
}
terror.Log(sctx.GetSessionVars().SetSystemVar(variable.TxnIsolation, ast.ReadCommitted))
defer func() {
terror.Log(sctx.GetSessionVars().SetSystemVar(variable.TiDBBuildStatsConcurrency, oriStats))
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,8 @@ var defaultSysVars = []*SysVar{
}, GetGlobal: func(s *SessionVars) (string, error) {
return BoolToOnOff(EnableTmpStorageOnOOM.Load()), nil
}},
{Scope: ScopeGlobal, Name: TiDBAutoBuildStatsConcurrency, Value: strconv.Itoa(DefAutoBuildStatsConcurrency), Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency},
{Scope: ScopeGlobal, Name: TiDBSysProcScanConcurrency, Value: strconv.Itoa(DefTiDBSysProcScanConcurrency), Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency},

/* The system variables below have GLOBAL and SESSION scope */
{Scope: ScopeGlobal | ScopeSession, Name: TiDBRowFormatVersion, Value: strconv.Itoa(DefTiDBRowFormatV1), Type: TypeUnsigned, MinValue: 1, MaxValue: 2, SetGlobal: func(s *SessionVars, val string) error {
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 @@ -791,6 +791,10 @@ const (
TiDBDDLEnableFastReorg = "tidb_ddl_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"
)

// TiDB intentional limits
Expand Down Expand Up @@ -1007,6 +1011,8 @@ const (
DefTiDBEnableFastReorg = false
DefTiDBDDLEnableFastReorg = false
DefTiDBDDLDiskQuota = 100 * 1024 * 1024 * 1024 // 100GB
DefAutoBuildStatsConcurrency = 1
DefTiDBSysProcScanConcurrency = 1
)

// Process global variables.
Expand Down

0 comments on commit 77d372a

Please sign in to comment.