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

sessionctx: add variable tidb_analyze_version #21515

Merged
merged 3 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
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: 2},
}

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we'll use old stats by default and change it manually to enable refactored stats?

Copy link
Member Author

@winoros winoros Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, according to the PM, it should be turned to the newer one after we have fully tested it.

)

// 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