Skip to content

Commit

Permalink
sessionctx: add variable tidb_analyze_version
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Dec 6, 2020
1 parent 62fd2b7 commit 3d1b1d7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,7 @@ var builtinGlobalVariable = []string{
variable.TiDBEnableAsyncCommit,
variable.TiDBEnable1PC,
variable.TiDBGuaranteeExternalConsistency,
variable.TiDBAnalyzeVersion,
}

var (
Expand Down
6 changes: 6 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@ type SessionVars struct {
Enable1PC bool

GuaranteeExternalConsistency bool

// AnalyzeVersion indicates how TiDB collect and use analyzed statistics.
AnalyzeVersion int
}

// CheckAndGetTxnScope will return the transaction scope we should use in the current session.
Expand Down Expand Up @@ -911,6 +914,7 @@ func NewSessionVars() *SessionVars {
EnableAsyncCommit: DefTiDBEnableAsyncCommit,
Enable1PC: DefTiDBEnable1PC,
GuaranteeExternalConsistency: DefTiDBGuaranteeExternalConsistency,
AnalyzeVersion: DefTiDBAnalyzeVersion,
}
vars.KVVars = kv.NewVariables(&vars.Killed)
vars.Concurrency = Concurrency{
Expand Down Expand Up @@ -1627,6 +1631,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error {
s.Enable1PC = TiDBOptOn(val)
case TiDBGuaranteeExternalConsistency:
s.GuaranteeExternalConsistency = TiDBOptOn(val)
case TiDBAnalyzeVersion:
s.AnalyzeVersion = tidbOptPositiveInt32(val, DefTiDBAnalyzeVersion)
}
s.systems[name] = val
return nil
Expand Down
1 change: 1 addition & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableAsyncCommit, Value: BoolToOnOff(DefTiDBEnableAsyncCommit), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnable1PC, Value: BoolToOnOff(DefTiDBEnable1PC), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBGuaranteeExternalConsistency, Value: BoolToOnOff(DefTiDBGuaranteeExternalConsistency), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAnalyzeVersion, Value: strconv.Itoa(DefTiDBAnalyzeVersion), Type: TypeInt, MinValue: 1, MaxValue: 1},
}

// SynonymsSysVariables is synonyms of system variables.
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ const (

// TiDBGuaranteeExternalConsistency indicates whether maintain the external consistency.
TiDBGuaranteeExternalConsistency = "tidb_guarantee_external_consistency"

// TiDBAnalyzeVersion indicates the how tidb collects the analyzed statistics and how use to it.
TiDBAnalyzeVersion = "tidb_analyze_version"
)

// Default TiDB system variable values.
Expand Down Expand Up @@ -601,6 +604,7 @@ const (
DefTiDBEnableAsyncCommit = false
DefTiDBEnable1PC = false
DefTiDBGuaranteeExternalConsistency = false
DefTiDBAnalyzeVersion = 1
)

// Process global variables.
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/varsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (s *testVarsutilSuite) TestNewSessionVars(c *C) {
c.Assert(vars.AllowAutoRandExplicitInsert, Equals, DefTiDBAllowAutoRandExplicitInsert)
c.Assert(vars.ShardAllocateStep, Equals, int64(DefTiDBShardAllocateStep))
c.Assert(vars.EnableChangeColumnType, Equals, DefTiDBChangeColumnType)
c.Assert(vars.AnalyzeVersion, Equals, DefTiDBAnalyzeVersion)

assertFieldsGreaterThanZero(c, reflect.ValueOf(vars.MemQuota))
assertFieldsGreaterThanZero(c, reflect.ValueOf(vars.BatchSize))
Expand Down Expand Up @@ -488,6 +489,9 @@ func (s *testVarsutilSuite) TestVarsutil(c *C) {

err = SetSessionSystemVar(v, "UnknownVariable", types.NewStringDatum("on"))
c.Assert(err, ErrorMatches, ".*]Unknown system variable 'UnknownVariable'")

err = SetSessionSystemVar(v, TiDBAnalyzeVersion, types.NewStringDatum("3"))
c.Assert(err, ErrorMatches, ".*Variable 'tidb_analyze_version' can't be set to the value of '3'")
}

func (s *testVarsutilSuite) TestSetOverflowBehave(c *C) {
Expand Down

0 comments on commit 3d1b1d7

Please sign in to comment.