Skip to content

Commit d381d84

Browse files
spongedujackysp
authored andcommitted
executor,sessionctx: refine output format for tidb-specific variables of boolean type (pingcap#11239)
1 parent 9b82445 commit d381d84

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

executor/set_test.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,25 @@ func (s *testSuite2) TestValidateSetVar(c *C) {
429429
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
430430

431431
tk.MustExec("set @@tidb_batch_delete='On';")
432+
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("1"))
432433
tk.MustExec("set @@tidb_batch_delete='oFf';")
434+
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("0"))
433435
tk.MustExec("set @@tidb_batch_delete=1;")
436+
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("1"))
434437
tk.MustExec("set @@tidb_batch_delete=0;")
438+
tk.MustQuery("select @@tidb_batch_delete;").Check(testkit.Rows("0"))
439+
440+
tk.MustExec("set @@tidb_opt_agg_push_down=off;")
441+
tk.MustQuery("select @@tidb_opt_agg_push_down;").Check(testkit.Rows("0"))
442+
443+
tk.MustExec("set @@tidb_constraint_check_in_place=on;")
444+
tk.MustQuery("select @@tidb_constraint_check_in_place;").Check(testkit.Rows("1"))
445+
446+
tk.MustExec("set @@tidb_general_log=0;")
447+
tk.MustQuery("select @@tidb_general_log;").Check(testkit.Rows("0"))
448+
449+
tk.MustExec("set @@tidb_enable_streaming=1;")
450+
tk.MustQuery("select @@tidb_enable_streaming;").Check(testkit.Rows("1"))
435451

436452
_, err = tk.Exec("set @@tidb_batch_delete=3;")
437453
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
@@ -789,9 +805,9 @@ func (s *testSuite2) TestEnableNoopFunctionsVar(c *C) {
789805
_, err = tk.Exec(`set tidb_enable_noop_functions=11`)
790806
c.Assert(err, NotNil)
791807
tk.MustExec(`set tidb_enable_noop_functions="off";`)
792-
tk.MustQuery(`select @@tidb_enable_noop_functions;`).Check(testkit.Rows("off"))
808+
tk.MustQuery(`select @@tidb_enable_noop_functions;`).Check(testkit.Rows("0"))
793809
tk.MustExec(`set tidb_enable_noop_functions="on";`)
794-
tk.MustQuery(`select @@tidb_enable_noop_functions;`).Check(testkit.Rows("on"))
810+
tk.MustQuery(`select @@tidb_enable_noop_functions;`).Check(testkit.Rows("1"))
795811
tk.MustExec(`set tidb_enable_noop_functions=0;`)
796812
tk.MustQuery(`select @@tidb_enable_noop_functions;`).Check(testkit.Rows("0"))
797813
}

sessionctx/variable/varsutil.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,16 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
374374
return "1", nil
375375
}
376376
return value, ErrWrongValueForVar.GenWithStackByArgs(name, value)
377-
case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, LogBin,
377+
case TiDBSkipUTF8Check, TiDBOptAggPushDown,
378+
TiDBOptInSubqToJoinAndAgg, TiDBEnableFastAnalyze,
379+
TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming,
380+
TiDBBatchDelete, TiDBBatchCommit, TiDBEnableCascadesPlanner, TiDBEnableWindowFunction,
381+
TiDBCheckMb4ValueInUTF8, TiDBLowResolutionTSO, TiDBEnableIndexMerge, TiDBEnableNoopFuncs,
382+
TiDBScatterRegion, TiDBGeneralLog, TiDBConstraintCheckInPlace:
383+
fallthrough
384+
case GeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, LogBin,
378385
CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, PseudoSlaveMode, LowPriorityUpdates,
379-
SkipNameResolve, SQLSafeUpdates, TiDBConstraintCheckInPlace, serverReadOnly, SlaveAllowBatching,
386+
SkipNameResolve, SQLSafeUpdates, serverReadOnly, SlaveAllowBatching,
380387
Flush, PerformanceSchema, LocalInFile, ShowOldTemporals, KeepFilesOnCreate, AutoCommit,
381388
SQLWarnings, UniqueChecks, OldAlterTable, LogBinTrustFunctionCreators, SQLBigSelects,
382389
BinlogDirectNonTransactionalUpdates, SQLQuoteShowCreate, AutomaticSpPrivileges,
@@ -415,16 +422,6 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
415422
}
416423
}
417424
return value, ErrWrongValueForVar.GenWithStackByArgs(name, value)
418-
case TiDBSkipUTF8Check, TiDBOptAggPushDown,
419-
TiDBOptInSubqToJoinAndAgg, TiDBEnableFastAnalyze,
420-
TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming,
421-
TiDBBatchDelete, TiDBBatchCommit, TiDBEnableCascadesPlanner, TiDBEnableWindowFunction,
422-
TiDBCheckMb4ValueInUTF8, TiDBLowResolutionTSO, TiDBEnableIndexMerge, TiDBEnableNoopFuncs,
423-
TiDBScatterRegion:
424-
if strings.EqualFold(value, "ON") || value == "1" || strings.EqualFold(value, "OFF") || value == "0" {
425-
return value, nil
426-
}
427-
return value, ErrWrongValueForVar.GenWithStackByArgs(name, value)
428425
case MaxExecutionTime:
429426
return checkUInt64SystemVar(name, value, 0, math.MaxUint64, vars)
430427
case TiDBEnableTablePartition:

0 commit comments

Comments
 (0)