diff --git a/executor/set_test.go b/executor/set_test.go index 77ab1b1d26c1a..9be1f1794ce1c 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -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) { diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index ebd1eed637ddd..60543c00d334e 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -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) diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 518b88e45de80..ee01348a76441 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -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