Skip to content

Commit

Permalink
executor, sessionctx/variable: convert some system variables to diffe…
Browse files Browse the repository at this point in the history
…rent builtin types (#35143)

close #35048
  • Loading branch information
gogim1 authored Jun 16, 2022
1 parent d25adf0 commit 79d9d6f
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 15 deletions.
86 changes: 84 additions & 2 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ func TestSetVar(t *testing.T) {
tk.MustExec("set session ddl_slow_threshold=\"54321\"")
tk.MustQuery("show variables like 'ddl_slow_threshold'").Check(testkit.Rows("ddl_slow_threshold 54321"))
require.Equal(t, uint32(54321), variable.DDLSlowOprThreshold)
tk.MustExec("set @@global.ddl_slow_threshold=-1")
tk.MustQuery("select @@global.ddl_slow_threshold").Check(testkit.Rows(strconv.Itoa(variable.DefTiDBDDLSlowOprThreshold)))
require.Equal(t, uint32(variable.DefTiDBDDLSlowOprThreshold), variable.DDLSlowOprThreshold)
require.Error(t, tk.ExecToErr("set @@global.ddl_slow_threshold=abc"))
tk.MustQuery("select @@global.ddl_slow_threshold").Check(testkit.Rows(strconv.Itoa(variable.DefTiDBDDLSlowOprThreshold)))
require.Equal(t, uint32(variable.DefTiDBDDLSlowOprThreshold), variable.DDLSlowOprThreshold)

// Test set transaction isolation level, which is equivalent to setting variable "tx_isolation".
tk.MustExec("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED")
Expand Down Expand Up @@ -221,6 +227,33 @@ func TestSetVar(t *testing.T) {
tk.MustExec("set @@tidb_pprof_sql_cpu = 1")
tk.MustExec("set @@tidb_pprof_sql_cpu = 0")

tk.MustExec(`set @@block_encryption_mode = "aes-128-ecb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-128-ecb"))
tk.MustExec(`set @@block_encryption_mode = "aes-192-ecb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-192-ecb"))
tk.MustExec(`set @@block_encryption_mode = "aes-256-ecb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-256-ecb"))
tk.MustExec(`set @@block_encryption_mode = "aes-128-cbc"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-128-cbc"))
tk.MustExec(`set @@block_encryption_mode = "aes-192-cbc"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-192-cbc"))
tk.MustExec(`set @@block_encryption_mode = "aes-256-cbc"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-256-cbc"))
tk.MustExec(`set @@block_encryption_mode = "aes-128-ofb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-128-ofb"))
tk.MustExec(`set @@block_encryption_mode = "aes-192-ofb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-192-ofb"))
tk.MustExec(`set @@block_encryption_mode = "aes-256-ofb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-256-ofb"))
tk.MustExec(`set @@block_encryption_mode = "aes-128-cfb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-128-cfb"))
tk.MustExec(`set @@block_encryption_mode = "aes-192-cfb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-192-cfb"))
tk.MustExec(`set @@block_encryption_mode = "aes-256-cfb"`)
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-256-cfb"))
require.Error(t, tk.ExecToErr("set @@block_encryption_mode = 'abc'"))
tk.MustQuery(`select @@block_encryption_mode;`).Check(testkit.Rows("aes-256-cfb"))

tk.MustExec(`set @@global.tidb_force_priority = "no_priority"`)
tk.MustQuery(`select @@global.tidb_force_priority;`).Check(testkit.Rows("NO_PRIORITY"))
tk.MustExec(`set @@global.tidb_force_priority = "low_priority"`)
Expand All @@ -229,8 +262,57 @@ func TestSetVar(t *testing.T) {
tk.MustQuery(`select @@global.tidb_force_priority;`).Check(testkit.Rows("HIGH_PRIORITY"))
tk.MustExec(`set @@global.tidb_force_priority = "delayed"`)
tk.MustQuery(`select @@global.tidb_force_priority;`).Check(testkit.Rows("DELAYED"))
tk.MustExec(`set @@global.tidb_force_priority = "abc"`)
tk.MustQuery(`select @@global.tidb_force_priority;`).Check(testkit.Rows("NO_PRIORITY"))
require.Error(t, tk.ExecToErr("set global tidb_force_priority = 'abc'"))
tk.MustQuery(`select @@global.tidb_force_priority;`).Check(testkit.Rows("DELAYED"))

tk.MustExec(`set @@session.tidb_ddl_reorg_priority = "priority_low"`)
tk.MustQuery(`select @@session.tidb_ddl_reorg_priority;`).Check(testkit.Rows("PRIORITY_LOW"))
tk.MustExec(`set @@session.tidb_ddl_reorg_priority = "priority_normal"`)
tk.MustQuery(`select @@session.tidb_ddl_reorg_priority;`).Check(testkit.Rows("PRIORITY_NORMAL"))
tk.MustExec(`set @@session.tidb_ddl_reorg_priority = "priority_high"`)
tk.MustQuery(`select @@session.tidb_ddl_reorg_priority;`).Check(testkit.Rows("PRIORITY_HIGH"))
require.Error(t, tk.ExecToErr("set session tidb_ddl_reorg_priority = 'abc'"))
tk.MustQuery(`select @@session.tidb_ddl_reorg_priority;`).Check(testkit.Rows("PRIORITY_HIGH"))

tk.MustExec("set tidb_opt_write_row_id = 1")
tk.MustQuery(`select @@session.tidb_opt_write_row_id;`).Check(testkit.Rows("1"))
tk.MustExec("set tidb_opt_write_row_id = 0")
tk.MustQuery(`select @@session.tidb_opt_write_row_id;`).Check(testkit.Rows("0"))
tk.MustExec("set tidb_opt_write_row_id = true")
tk.MustQuery(`select @@session.tidb_opt_write_row_id;`).Check(testkit.Rows("1"))
tk.MustExec("set tidb_opt_write_row_id = false")
tk.MustQuery(`select @@session.tidb_opt_write_row_id;`).Check(testkit.Rows("0"))
tk.MustExec("set tidb_opt_write_row_id = On")
tk.MustQuery(`select @@session.tidb_opt_write_row_id;`).Check(testkit.Rows("1"))
tk.MustExec("set tidb_opt_write_row_id = Off")
tk.MustQuery(`select @@session.tidb_opt_write_row_id;`).Check(testkit.Rows("0"))
require.Error(t, tk.ExecToErr("set tidb_opt_write_row_id = 'abc'"))
tk.MustQuery(`select @@session.tidb_opt_write_row_id;`).Check(testkit.Rows("0"))

tk.MustExec("set tidb_checksum_table_concurrency = 42")
tk.MustQuery(`select @@tidb_checksum_table_concurrency;`).Check(testkit.Rows("42"))
require.Error(t, tk.ExecToErr("set tidb_checksum_table_concurrency = 'abc'"))
tk.MustQuery(`select @@tidb_checksum_table_concurrency;`).Check(testkit.Rows("42"))
tk.MustExec("set tidb_checksum_table_concurrency = 257")
tk.MustQuery(`select @@tidb_checksum_table_concurrency;`).Check(testkit.Rows(strconv.Itoa(variable.MaxConfigurableConcurrency)))

tk.MustExec("set tidb_build_stats_concurrency = 42")
tk.MustQuery(`select @@tidb_build_stats_concurrency;`).Check(testkit.Rows("42"))
require.Error(t, tk.ExecToErr("set tidb_build_stats_concurrency = 'abc'"))
tk.MustQuery(`select @@tidb_build_stats_concurrency;`).Check(testkit.Rows("42"))
tk.MustExec("set tidb_build_stats_concurrency = 257")
tk.MustQuery(`select @@tidb_build_stats_concurrency;`).Check(testkit.Rows(strconv.Itoa(variable.MaxConfigurableConcurrency)))

tk.MustExec(`set tidb_partition_prune_mode = "static"`)
tk.MustQuery(`select @@tidb_partition_prune_mode;`).Check(testkit.Rows("static"))
tk.MustExec(`set tidb_partition_prune_mode = "dynamic"`)
tk.MustQuery(`select @@tidb_partition_prune_mode;`).Check(testkit.Rows("dynamic"))
tk.MustExec(`set tidb_partition_prune_mode = "static-only"`)
tk.MustQuery(`select @@tidb_partition_prune_mode;`).Check(testkit.Rows("static"))
tk.MustExec(`set tidb_partition_prune_mode = "dynamic-only"`)
tk.MustQuery(`select @@tidb_partition_prune_mode;`).Check(testkit.Rows("dynamic"))
require.Error(t, tk.ExecToErr("set tidb_partition_prune_mode = 'abc'"))
tk.MustQuery(`select @@tidb_partition_prune_mode;`).Check(testkit.Rows("dynamic"))

tk.MustExec("set tidb_constraint_check_in_place = 1")
tk.MustQuery(`select @@session.tidb_constraint_check_in_place;`).Check(testkit.Rows("1"))
Expand Down
26 changes: 13 additions & 13 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeNone, Name: DataDir, Value: "/usr/local/mysql/data/"},
{Scope: ScopeNone, Name: Socket, Value: ""},
{Scope: ScopeNone, Name: "license", Value: "Apache License 2.0"},
{Scope: ScopeNone, Name: "have_ssl", Value: "DISABLED"},
{Scope: ScopeNone, Name: "have_openssl", Value: "DISABLED"},
{Scope: ScopeNone, Name: "have_ssl", Value: "DISABLED", Type: TypeBool},
{Scope: ScopeNone, Name: "have_openssl", Value: "DISABLED", Type: TypeBool},
{Scope: ScopeNone, Name: "ssl_ca", Value: ""},
{Scope: ScopeNone, Name: "ssl_cert", Value: ""},
{Scope: ScopeNone, Name: "ssl_key", Value: ""},
Expand All @@ -84,10 +84,10 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeSession, Name: ErrorCount, Value: "0", ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return strconv.Itoa(int(s.SysErrorCount)), nil
}},
{Scope: ScopeSession, Name: LastInsertID, Value: "", skipInit: true, GetSession: func(s *SessionVars) (string, error) {
{Scope: ScopeSession, Name: LastInsertID, Value: "", skipInit: true, Type: TypeInt, AllowEmpty: true, MinValue: 0, MaxValue: math.MaxInt64, GetSession: func(s *SessionVars) (string, error) {
return strconv.FormatUint(s.StmtCtx.PrevLastInsertID, 10), nil
}},
{Scope: ScopeSession, Name: Identity, Value: "", skipInit: true, GetSession: func(s *SessionVars) (string, error) {
{Scope: ScopeSession, Name: Identity, Value: "", skipInit: true, Type: TypeInt, AllowEmpty: true, MinValue: 0, MaxValue: math.MaxInt64, GetSession: func(s *SessionVars) (string, error) {
return strconv.FormatUint(s.StmtCtx.PrevLastInsertID, 10), nil
}},
/* TiDB specific variables */
Expand Down Expand Up @@ -152,11 +152,11 @@ var defaultSysVars = []*SysVar{
s.AllowDistinctAggPushDown = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBOptWriteRowID, Value: BoolToOnOff(DefOptWriteRowID), skipInit: true, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBOptWriteRowID, Value: BoolToOnOff(DefOptWriteRowID), Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
s.AllowWriteRowID = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBChecksumTableConcurrency, skipInit: true, Value: strconv.Itoa(DefChecksumTableConcurrency)},
{Scope: ScopeSession, Name: TiDBChecksumTableConcurrency, skipInit: true, Value: strconv.Itoa(DefChecksumTableConcurrency), Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency},
{Scope: ScopeSession, Name: TiDBBatchInsert, Value: BoolToOnOff(DefBatchInsert), Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
s.BatchInsert = TiDBOptOn(val)
return nil
Expand All @@ -169,7 +169,7 @@ var defaultSysVars = []*SysVar{
s.BatchCommit = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBCurrentTS, Value: strconv.Itoa(DefCurretTS), ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
{Scope: ScopeSession, Name: TiDBCurrentTS, Value: strconv.Itoa(DefCurretTS), Type: TypeInt, AllowEmpty: true, MinValue: 0, MaxValue: math.MaxInt64, ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return strconv.FormatUint(s.TxnCtx.StartTS, 10), nil
}},
{Scope: ScopeSession, Name: TiDBLastTxnInfo, Value: strconv.Itoa(DefCurretTS), ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
Expand Down Expand Up @@ -224,7 +224,7 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeSession, Name: TiDBConfig, Value: "", ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return config.GetJSONConfig()
}},
{Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW", skipInit: true, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW", Type: TypeEnum, skipInit: true, PossibleValues: []string{"PRIORITY_LOW", "PRIORITY_NORMAL", "PRIORITY_HIGH"}, SetSession: func(s *SessionVars, val string) error {
s.setDDLReorgPriority(val)
return nil
}},
Expand Down Expand Up @@ -373,13 +373,13 @@ var defaultSysVars = []*SysVar{
}
return val, nil
}},
{Scope: ScopeInstance, Name: TiDBDDLSlowOprThreshold, Value: strconv.Itoa(DefTiDBDDLSlowOprThreshold), skipInit: true, SetGlobal: func(s *SessionVars, val string) error {
{Scope: ScopeInstance, Name: TiDBDDLSlowOprThreshold, Value: strconv.Itoa(DefTiDBDDLSlowOprThreshold), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32, skipInit: true, SetGlobal: func(s *SessionVars, val string) error {
atomic.StoreUint32(&DDLSlowOprThreshold, uint32(tidbOptPositiveInt32(val, DefTiDBDDLSlowOprThreshold)))
return nil
}, GetGlobal: func(s *SessionVars) (string, error) {
return strconv.FormatUint(uint64(atomic.LoadUint32(&DDLSlowOprThreshold)), 10), nil
}},
{Scope: ScopeInstance, Name: TiDBForcePriority, skipInit: true, Value: mysql.Priority2Str[DefTiDBForcePriority], SetGlobal: func(s *SessionVars, val string) error {
{Scope: ScopeInstance, Name: TiDBForcePriority, skipInit: true, Value: mysql.Priority2Str[DefTiDBForcePriority], Type: TypeEnum, PossibleValues: []string{"NO_PRIORITY", "LOW_PRIORITY", "HIGH_PRIORITY", "DELAYED"}, SetGlobal: func(s *SessionVars, val string) error {
atomic.StoreInt32(&ForcePriority, int32(mysql.Str2Priority(val)))
return nil
}, GetGlobal: func(s *SessionVars) (string, error) {
Expand Down Expand Up @@ -1001,7 +1001,7 @@ var defaultSysVars = []*SysVar{
s.WindowingUseHighPrecision = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: BlockEncryptionMode, Value: "aes-128-ecb"},
{Scope: ScopeGlobal | ScopeSession, Name: BlockEncryptionMode, Value: "aes-128-ecb", Type: TypeEnum, PossibleValues: []string{"aes-128-ecb", "aes-192-ecb", "aes-256-ecb", "aes-128-cbc", "aes-192-cbc", "aes-256-cbc", "aes-128-ofb", "aes-192-ofb", "aes-256-ofb", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb"}},
/* TiDB specific variables */
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAllowMPPExecution, Type: TypeBool, Value: BoolToOnOff(DefTiDBAllowMPPExecution), SetSession: func(s *SessionVars, val string) error {
s.allowMPPExecution = TiDBOptOn(val)
Expand All @@ -1023,7 +1023,7 @@ var defaultSysVars = []*SysVar{
s.BroadcastJoinThresholdSize = TidbOptInt64(val, DefBroadcastJoinThresholdSize)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBuildStatsConcurrency, skipInit: true, Value: strconv.Itoa(DefBuildStatsConcurrency)},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBuildStatsConcurrency, skipInit: true, Value: strconv.Itoa(DefBuildStatsConcurrency), Type: TypeInt, MinValue: 1, MaxValue: MaxConfigurableConcurrency},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptCartesianBCJ, Value: strconv.Itoa(DefOptCartesianBCJ), Type: TypeInt, MinValue: 0, MaxValue: 2, SetSession: func(s *SessionVars, val string) error {
s.AllowCartesianBCJ = TidbOptInt(val, DefOptCartesianBCJ)
return nil
Expand Down Expand Up @@ -1441,7 +1441,7 @@ var defaultSysVars = []*SysVar{
s.EnableClusteredIndex = TiDBOptEnableClustered(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBPartitionPruneMode, Value: DefTiDBPartitionPruneMode, Type: TypeStr, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBPartitionPruneMode, Value: DefTiDBPartitionPruneMode, Type: TypeEnum, PossibleValues: []string{"static", "dynamic", "static-only", "dynamic-only"}, 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

0 comments on commit 79d9d6f

Please sign in to comment.