Skip to content

Commit

Permalink
planner: Introduce a new global variable to control the historical st…
Browse files Browse the repository at this point in the history
…atistics feature (#30646)
  • Loading branch information
An-DJ authored Dec 14, 2021
1 parent dd7f71f commit c30d34f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ func (s *testSerialSuite1) TestSetVar(c *C) {
tk.MustExec("set global tidb_enable_tso_follower_proxy = 0")
tk.MustQuery("select @@tidb_enable_tso_follower_proxy").Check(testkit.Rows("0"))
c.Assert(tk.ExecToErr("set tidb_enable_tso_follower_proxy = 1"), NotNil)

tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_enable_historical_stats = 1")
tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_enable_historical_stats = 0")
tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("0"))
}

func (s *testSuite5) TestTruncateIncorrectIntSessionVar(c *C) {
Expand Down
6 changes: 5 additions & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,11 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeSession, Name: PluginDir, Value: "/data/deploy/plugin", GetSession: func(s *SessionVars) (string, error) {
return config.GetGlobalConfig().Plugin.Dir, nil
}},

{Scope: ScopeGlobal, Name: TiDBEnableHistoricalStats, Value: Off, Type: TypeBool, GetGlobal: func(s *SessionVars) (string, error) {
return getTiDBTableValue(s, "tidb_enable_historical_stats", Off)
}, SetGlobal: func(s *SessionVars, val string) error {
return setTiDBTableValue(s, "tidb_enable_historical_stats", val, "Current historical statistics enable status")
}},
/* tikv gc metrics */
{Scope: ScopeGlobal, Name: TiDBGCEnable, Value: On, Type: TypeBool, GetGlobal: func(s *SessionVars) (string, error) {
return getTiDBTableValue(s, "tikv_gc_enable", On)
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ const (
TiDBGCScanLockMode = "tidb_gc_scan_lock_mode"
// TiDBEnableEnhancedSecurity restricts SUPER users from certain operations.
TiDBEnableEnhancedSecurity = "tidb_enable_enhanced_security"
// TiDBEnableHistoricalStats enables the historical statistics feature (default off)
TiDBEnableHistoricalStats = "tidb_enable_historical_stats"
)

// TiDB intentional limits
Expand Down

0 comments on commit c30d34f

Please sign in to comment.