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

executor, variable: move hidden variables to struct #24304

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ func (e *ShowExec) fetchShowVariables() (err error) {
// otherwise, fetch the value from table `mysql.Global_Variables`.
for _, v := range variable.GetSysVars() {
if v.Scope != variable.ScopeSession {
if variable.FilterImplicitFeatureSwitch(v) {
if v.Hidden {
continue
}
value, err = variable.GetGlobalSystemVar(sessionVars, v.Name)
Expand All @@ -689,7 +689,7 @@ func (e *ShowExec) fetchShowVariables() (err error) {
// If it is a session only variable, use the default value defined in code,
// otherwise, fetch the value from table `mysql.Global_Variables`.
for _, v := range variable.GetSysVars() {
if variable.FilterImplicitFeatureSwitch(v) {
if v.Hidden {
continue
}
value, err = variable.GetSessionSystemVar(sessionVars, v.Name)
Expand Down
14 changes: 6 additions & 8 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ func (s *testSuite5) TestShowVar(c *C) {
sessionVars := make([]string, 0, len(variable.GetSysVars()))
globalVars := make([]string, 0, len(variable.GetSysVars()))
for _, v := range variable.GetSysVars() {
if variable.FilterImplicitFeatureSwitch(v) {
if v.Hidden {
continue
}

Expand Down Expand Up @@ -1264,13 +1264,11 @@ func (s *testSuite5) TestShowVar(c *C) {
res = tk.MustQuery(showSQL)
c.Check(res.Rows(), HasLen, len(globalVars))

// Test for switch variable which shouldn't seen by users.
for _, one := range variable.FeatureSwitchVariables {
res := tk.MustQuery("show variables like '" + one + "'")
c.Check(res.Rows(), HasLen, 0)
res = tk.MustQuery("show global variables like '" + one + "'")
c.Check(res.Rows(), HasLen, 0)
}
// Test a known hidden variable.
res = tk.MustQuery("show variables like '" + variable.TiDBPartitionPruneMode + "'")
c.Check(res.Rows(), HasLen, 0)
res = tk.MustQuery("show global variables like '" + variable.TiDBPartitionPruneMode + "'")
c.Check(res.Rows(), HasLen, 0)
}

func (s *testSuite5) TestIssue19507(c *C) {
Expand Down
26 changes: 14 additions & 12 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type SysVar struct {
SetSession func(*SessionVars, string) error
// IsHintUpdatable indicate whether it's updatable via SET_VAR() hint (optional)
IsHintUpdatable bool
// Hidden means that it still responds to SET but doesn't show up in SHOW VARIABLES
Hidden bool
}

// SetSessionFromHook calls the SetSession func if it exists.
Expand Down Expand Up @@ -1069,19 +1071,19 @@ var defaultSysVars = []*SysVar{
SetMaxDeltaSchemaCount(tidbOptInt64(val, DefTiDBMaxDeltaSchemaCount))
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableChangeColumnType = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBChangeMultiSchema), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBChangeMultiSchema), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableChangeMultiSchema = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBEnablePointGetCache, Value: BoolToOnOff(DefTiDBPointGetCache), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal, Name: TiDBEnablePointGetCache, Value: BoolToOnOff(DefTiDBPointGetCache), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnablePointGetCache = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBEnableAlterPlacement, Value: BoolToOnOff(DefTiDBEnableAlterPlacement), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal, Name: TiDBEnableAlterPlacement, Value: BoolToOnOff(DefTiDBEnableAlterPlacement), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableAlterPlacement = TiDBOptOn(val)
return nil
}},
Expand Down Expand Up @@ -1177,7 +1179,7 @@ var defaultSysVars = []*SysVar{
s.EvolvePlanBaselines = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableExtendedStats, Value: BoolToOnOff(false), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableExtendedStats, Value: BoolToOnOff(false), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableExtendedStats = TiDBOptOn(val)
return nil
}},
Expand Down Expand Up @@ -1285,7 +1287,7 @@ var defaultSysVars = []*SysVar{
s.EnableClusteredIndex = TiDBOptEnableClustered(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBPartitionPruneMode, Value: string(Static), Type: TypeStr, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBPartitionPruneMode, Value: string(Static), Hidden: true, Type: TypeStr, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
mode := PartitionPruneMode(normalizedValue).Update()
if !mode.Valid() {
return normalizedValue, ErrWrongTypeForVar.GenWithStackByArgs(TiDBPartitionPruneMode)
Expand Down Expand Up @@ -1313,19 +1315,19 @@ var defaultSysVars = []*SysVar{
s.EnableAmendPessimisticTxn = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableAsyncCommit, Value: BoolToOnOff(DefTiDBEnableAsyncCommit), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableAsyncCommit, Value: BoolToOnOff(DefTiDBEnableAsyncCommit), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableAsyncCommit = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnable1PC, Value: BoolToOnOff(DefTiDBEnable1PC), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnable1PC, Value: BoolToOnOff(DefTiDBEnable1PC), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.Enable1PC = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBGuaranteeLinearizability, Value: BoolToOnOff(DefTiDBGuaranteeLinearizability), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBGuaranteeLinearizability, Value: BoolToOnOff(DefTiDBGuaranteeLinearizability), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.GuaranteeLinearizability = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAnalyzeVersion, Value: strconv.Itoa(DefTiDBAnalyzeVersion), Type: TypeInt, MinValue: 1, MaxValue: 2, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAnalyzeVersion, Value: strconv.Itoa(DefTiDBAnalyzeVersion), Hidden: true, Type: TypeInt, MinValue: 1, MaxValue: 2, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
if normalizedValue == "2" && FeedbackProbability.Load() > 0 {
var original string
var err error
Expand All @@ -1345,11 +1347,11 @@ var defaultSysVars = []*SysVar{
s.AnalyzeVersion = tidbOptPositiveInt32(val, DefTiDBAnalyzeVersion)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableIndexMergeJoin, Value: BoolToOnOff(DefTiDBEnableIndexMergeJoin), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableIndexMergeJoin, Value: BoolToOnOff(DefTiDBEnableIndexMergeJoin), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableIndexMergeJoin = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBTrackAggregateMemoryUsage, Value: BoolToOnOff(DefTiDBTrackAggregateMemoryUsage), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBTrackAggregateMemoryUsage, Value: BoolToOnOff(DefTiDBTrackAggregateMemoryUsage), Hidden: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.TrackAggregateMemoryUsage = TiDBOptOn(val)
return nil
}},
Expand Down
26 changes: 0 additions & 26 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,29 +701,3 @@ var (
DefExecutorConcurrency = 5
MemoryUsageAlarmRatio = atomic.NewFloat64(config.GetGlobalConfig().Performance.MemoryUsageAlarmRatio)
)

// FeatureSwitchVariables is used to filter result of show variables, these switches should be turn blind to users.
var FeatureSwitchVariables = []string{
TiDBEnableChangeColumnType,
TiDBEnablePointGetCache,
TiDBEnableAlterPlacement,
TiDBEnableChangeMultiSchema,
TiDBEnableAsyncCommit,
TiDBEnable1PC,
TiDBGuaranteeLinearizability,
TiDBTrackAggregateMemoryUsage,
TiDBAnalyzeVersion,
TiDBPartitionPruneMode,
TiDBEnableExtendedStats,
TiDBEnableIndexMergeJoin,
}

// FilterImplicitFeatureSwitch is used to filter result of show variables, these switches should be turn blind to users.
func FilterImplicitFeatureSwitch(sysVar *SysVar) bool {
for _, one := range FeatureSwitchVariables {
if one == sysVar.Name {
return true
}
}
return false
}