Skip to content

Commit

Permalink
Merge branch 'master' into fix-37058
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Aug 23, 2022
2 parents e865342 + 11dbd0b commit 89ed0e9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions bindinfo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ go_test(
],
embed = [":bindinfo"],
flaky = True,
shard_count = 50,
deps = [
"//config",
"//domain",
Expand Down
8 changes: 7 additions & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeNone, Name: TiDBAllowFunctionForExpressionIndex, ReadOnly: true, Value: collectAllowFuncName4ExpressionIndex()},

/* The system variables below have SESSION scope */
{Scope: ScopeSession, Name: Timestamp, Value: DefTimestamp, MinValue: 0, MaxValue: 2147483647, Type: TypeFloat, GetSession: func(s *SessionVars) (string, error) {
{Scope: ScopeSession, Name: Timestamp, Value: DefTimestamp, MinValue: 0, MaxValue: math.MaxInt32, Type: TypeFloat, GetSession: func(s *SessionVars) (string, error) {
if timestamp, ok := s.systems[Timestamp]; ok && timestamp != DefTimestamp {
return timestamp, nil
}
Expand All @@ -86,6 +86,12 @@ var defaultSysVars = []*SysVar{
}, GetStateValue: func(s *SessionVars) (string, bool, error) {
timestamp, ok := s.systems[Timestamp]
return timestamp, ok && timestamp != DefTimestamp, nil
}, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
val := tidbOptFloat64(originalValue, DefTimestampFloat)
if val > math.MaxInt32 {
return originalValue, ErrWrongValueForVar.GenWithStackByArgs(Timestamp, originalValue)
}
return normalizedValue, nil
}},
{Scope: ScopeSession, Name: WarningCount, Value: "0", ReadOnly: true, GetSession: func(s *SessionVars) (string, error) {
return strconv.Itoa(s.SysWarningCount), nil
Expand Down
18 changes: 18 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,24 @@ func TestTimestamp(t *testing.T) {
require.NoError(t, err)
require.NotEqual(t, "", val)
require.NotEqual(t, "10", val)

// Test validating a value that less than the minimum one.
sv := GetSysVar(Timestamp)
_, err = sv.Validate(vars, "-5", ScopeSession)
require.NoError(t, err)
warn := vars.StmtCtx.GetWarnings()[0].Err
require.Equal(t, "[variable:1292]Truncated incorrect timestamp value: '-5'", warn.Error())

// Test validating values that larger than the maximum one.
_, err = sv.Validate(vars, "3147483698", ScopeSession)
require.Equal(t, "[variable:1231]Variable 'timestamp' can't be set to the value of '3147483698'", err.Error())

_, err = sv.Validate(vars, "2147483648", ScopeSession)
require.Equal(t, "[variable:1231]Variable 'timestamp' can't be set to the value of '2147483648'", err.Error())

// Test validating the maximum value.
_, err = sv.Validate(vars, "2147483647", ScopeSession)
require.NoError(t, err)
}

func TestIdentity(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ const (
DefTiDBRegardNULLAsPoint = true
DefEnablePlacementCheck = true
DefTimestamp = "0"
DefTimestampFloat = 0.0
DefTiDBEnableStmtSummary = true
DefTiDBStmtSummaryInternalQuery = false
DefTiDBStmtSummaryRefreshInterval = 1800
Expand Down
1 change: 1 addition & 0 deletions types/json/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//errno",
"//parser/mysql",
"//parser/terror",
"//util/dbterror",
"//util/hack",
Expand Down

0 comments on commit 89ed0e9

Please sign in to comment.