Skip to content

Commit

Permalink
cherry-pick manually
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 committed Apr 12, 2020
1 parent 4f03354 commit 420e9f1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
16 changes: 16 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,25 @@ func (s *testSuite5) TestValidateSetVar(c *C) {
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))

tk.MustExec("set @@tidb_batch_delete='On';")
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("1"))
tk.MustExec("set @@tidb_batch_delete='oFf';")
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("0"))
tk.MustExec("set @@tidb_batch_delete=1;")
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("1"))
tk.MustExec("set @@tidb_batch_delete=0;")
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("0"))

tk.MustExec("set @@tidb_opt_agg_push_down=off;")
tk.MustQuery("select @@tidb_opt_agg_push_down;").Check(testkit.Rows("0"))

tk.MustExec("set @@tidb_constraint_check_in_place=on;")
tk.MustQuery("select @@tidb_constraint_check_in_place;").Check(testkit.Rows("1"))

tk.MustExec("set @@tidb_general_log=0;")
tk.MustQuery("select @@tidb_general_log;").Check(testkit.Rows("0"))

tk.MustExec("set @@tidb_enable_streaming=1;")
tk.MustQuery("select @@tidb_enable_streaming;").Check(testkit.Rows("1"))

_, err = tk.Exec("set @@tidb_batch_delete=3;")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
Expand Down
6 changes: 3 additions & 3 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,14 @@ func (s *testSessionSuite) TestGlobalVarAccessor(c *C) {
result.Check(testkit.Rows("sql_select_limit 100000000000"))

result = tk.MustQuery("select @@global.autocommit;")
result.Check(testkit.Rows("ON"))
result.Check(testkit.Rows("1"))
result = tk.MustQuery("select @@autocommit;")
result.Check(testkit.Rows("ON"))
result.Check(testkit.Rows("1"))
tk.MustExec("set @@global.autocommit = 0;")
result = tk.MustQuery("select @@global.autocommit;")
result.Check(testkit.Rows("0"))
result = tk.MustQuery("select @@autocommit;")
result.Check(testkit.Rows("ON"))
result.Check(testkit.Rows("1"))
tk.MustExec("set @@global.autocommit=1")

_, err = tk.Exec("set global time_zone = 'timezone'")
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ var defaultSysVars = []*SysVar{
{ScopeGlobal, "table_open_cache", "2000"},
{ScopeNone, "log_slave_updates", "OFF"},
{ScopeNone, "performance_schema_events_stages_history_long_size", "10000"},
{ScopeGlobal | ScopeSession, "autocommit", "ON"},
{ScopeGlobal | ScopeSession, "autocommit", "1"},
{ScopeSession, "insert_id", ""},
{ScopeGlobal | ScopeSession, "default_tmp_storage_engine", "InnoDB"},
{ScopeGlobal | ScopeSession, "optimizer_search_depth", "62"},
Expand Down
17 changes: 7 additions & 10 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,22 +327,19 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
case WarningCount, ErrorCount:
return value, ErrReadOnly.GenWithStackByArgs(name)

case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, LogBin, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode,
PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates, TiDBConstraintCheckInPlace:
case AutocommitVar, TiDBGeneralLog, TiDBSkipUTF8Check, TiDBOptAggPushDown,
TiDBOptInSubqUnFolding, TiDBEnableTablePartition,
TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming,
TiDBBatchDelete, TiDBCheckMb4ValueInUTF8, TiDBScatterRegion, TiDBConstraintCheckInPlace:
fallthrough
case GeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, LogBin, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode,
PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates:
if strings.EqualFold(value, "ON") || value == "1" {
return "1", nil
} else if strings.EqualFold(value, "OFF") || value == "0" {
return "0", nil
}
return value, ErrWrongValueForVar.GenWithStackByArgs(name, value)
case AutocommitVar, TiDBSkipUTF8Check, TiDBOptAggPushDown,
TiDBOptInSubqUnFolding, TiDBEnableTablePartition,
TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming,
TiDBBatchDelete, TiDBCheckMb4ValueInUTF8, TiDBScatterRegion:
if strings.EqualFold(value, "ON") || value == "1" || strings.EqualFold(value, "OFF") || value == "0" {
return value, nil
}
return value, ErrWrongValueForVar.GenWithStackByArgs(name, value)
case TiDBDDLReorgBatchSize:
return checkUInt64SystemVar(name, value, uint64(MinDDLReorgBatchSize), uint64(MaxDDLReorgBatchSize), vars)
case MaxExecutionTime:
Expand Down

0 comments on commit 420e9f1

Please sign in to comment.