From 91fb5d3b4dd4a494a20cfdca5026c45b66704ada Mon Sep 17 00:00:00 2001 From: Arenatlx <314806019@qq.com> Date: Mon, 25 Dec 2023 18:31:57 +0800 Subject: [PATCH] This is an automated cherry-pick of #49760 Signed-off-by: ti-chi-bot --- sessionctx/stmtctx/stmtctx.go | 4 +- sessionctx/stmtctx/stmtctx_test.go | 118 +++++++++++++++++++++++++ sessionctx/variable/noop.go | 8 +- sessionctx/variable/session.go | 4 +- sessionctx/variable/sysvar.go | 135 +++++++++++++++++++++++++++-- sessionctx/variable/variable.go | 18 ++-- sessionctx/variable/varsutil.go | 14 +-- 7 files changed, 269 insertions(+), 32 deletions(-) diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index fc6c86fc11e3a..1731b9ba1d30d 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -1212,10 +1212,10 @@ func (sc *StatementContext) RecordRangeFallback(rangeMaxSize int64) { // If range fallback happens, it means ether the query is unreasonable(for example, several long IN lists) or tidb_opt_range_max_size is too small // and the generated plan is probably suboptimal. In that case we don't put it into plan cache. if sc.UseCache { - sc.SetSkipPlanCache(errors.Errorf("in-list is too long")) + sc.SetSkipPlanCache(errors.NewNoStackError("in-list is too long")) } if !sc.RangeFallback { - sc.AppendWarning(errors.Errorf("Memory capacity of %v bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen", rangeMaxSize)) + sc.AppendWarning(errors.NewNoStackErrorf("Memory capacity of %v bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen", rangeMaxSize)) sc.RangeFallback = true } } diff --git a/sessionctx/stmtctx/stmtctx_test.go b/sessionctx/stmtctx/stmtctx_test.go index 9a3951278befc..b74127b534616 100644 --- a/sessionctx/stmtctx/stmtctx_test.go +++ b/sessionctx/stmtctx/stmtctx_test.go @@ -296,3 +296,121 @@ func TestStmtHintsClone(t *testing.T) { } require.Equal(t, hints, *hints.Clone()) } +<<<<<<< HEAD:sessionctx/stmtctx/stmtctx_test.go +======= + +func TestNewStmtCtx(t *testing.T) { + sc := stmtctx.NewStmtCtx() + require.Equal(t, types.DefaultStmtFlags, sc.TypeFlags()) + require.Same(t, time.UTC, sc.TimeZone()) + require.Same(t, time.UTC, sc.TimeZone()) + sc.AppendWarning(errors.NewNoStackError("err1")) + warnings := sc.GetWarnings() + require.Equal(t, 1, len(warnings)) + require.Equal(t, stmtctx.WarnLevelWarning, warnings[0].Level) + require.Equal(t, "err1", warnings[0].Err.Error()) + + tz := time.FixedZone("UTC+1", 2*60*60) + sc = stmtctx.NewStmtCtxWithTimeZone(tz) + require.Equal(t, types.DefaultStmtFlags, sc.TypeFlags()) + require.Same(t, tz, sc.TimeZone()) + require.Same(t, tz, sc.TimeZone()) + sc.AppendWarning(errors.NewNoStackError("err2")) + warnings = sc.GetWarnings() + require.Equal(t, 1, len(warnings)) + require.Equal(t, stmtctx.WarnLevelWarning, warnings[0].Level) + require.Equal(t, "err2", warnings[0].Err.Error()) +} + +func TestSetStmtCtxTimeZone(t *testing.T) { + sc := stmtctx.NewStmtCtx() + require.Same(t, time.UTC, sc.TimeZone()) + tz := time.FixedZone("UTC+1", 2*60*60) + sc.SetTimeZone(tz) + require.Same(t, tz, sc.TimeZone()) +} + +func TestSetStmtCtxTypeFlags(t *testing.T) { + sc := stmtctx.NewStmtCtx() + require.Equal(t, types.DefaultStmtFlags, sc.TypeFlags()) + + sc.SetTypeFlags(types.FlagAllowNegativeToUnsigned | types.FlagSkipASCIICheck) + require.Equal(t, types.FlagAllowNegativeToUnsigned|types.FlagSkipASCIICheck, sc.TypeFlags()) + require.Equal(t, sc.TypeFlags(), sc.TypeFlags()) + + sc.SetTypeFlags(types.FlagSkipASCIICheck | types.FlagSkipUTF8Check | types.FlagTruncateAsWarning) + require.Equal(t, types.FlagSkipASCIICheck|types.FlagSkipUTF8Check|types.FlagTruncateAsWarning, sc.TypeFlags()) + require.Equal(t, sc.TypeFlags(), sc.TypeFlags()) +} + +func TestResetStmtCtx(t *testing.T) { + sc := stmtctx.NewStmtCtx() + require.Equal(t, types.DefaultStmtFlags, sc.TypeFlags()) + + tz := time.FixedZone("UTC+1", 2*60*60) + sc.SetTimeZone(tz) + sc.SetTypeFlags(types.FlagAllowNegativeToUnsigned | types.FlagSkipASCIICheck) + sc.AppendWarning(errors.NewNoStackError("err1")) + sc.InRestrictedSQL = true + sc.StmtType = "Insert" + + require.Same(t, tz, sc.TimeZone()) + require.Equal(t, types.FlagAllowNegativeToUnsigned|types.FlagSkipASCIICheck, sc.TypeFlags()) + require.Equal(t, 1, len(sc.GetWarnings())) + + sc.Reset() + require.Same(t, time.UTC, sc.TimeZone()) + require.Same(t, time.UTC, sc.TimeZone()) + require.Equal(t, types.DefaultStmtFlags, sc.TypeFlags()) + require.Equal(t, types.DefaultStmtFlags, sc.TypeFlags()) + require.False(t, sc.InRestrictedSQL) + require.Empty(t, sc.StmtType) + require.Equal(t, 0, len(sc.GetWarnings())) + sc.AppendWarning(errors.NewNoStackError("err2")) + warnings := sc.GetWarnings() + require.Equal(t, 1, len(warnings)) + require.Equal(t, stmtctx.WarnLevelWarning, warnings[0].Level) + require.Equal(t, "err2", warnings[0].Err.Error()) +} + +func TestStmtCtxID(t *testing.T) { + sc := stmtctx.NewStmtCtx() + currentID := sc.CtxID() + + cases := []struct { + fn func() *stmtctx.StatementContext + }{ + {func() *stmtctx.StatementContext { return stmtctx.NewStmtCtx() }}, + {func() *stmtctx.StatementContext { return stmtctx.NewStmtCtxWithTimeZone(time.Local) }}, + {func() *stmtctx.StatementContext { + sc.Reset() + return sc + }}, + } + + for _, c := range cases { + ctxID := c.fn().CtxID() + require.Greater(t, ctxID, currentID) + currentID = ctxID + } +} + +func TestErrCtx(t *testing.T) { + sc := stmtctx.NewStmtCtx() + // the default errCtx + err := types.ErrTruncated + require.Error(t, sc.HandleError(err)) + + // reset the types flags will re-initialize the error flag + sc.SetTypeFlags(types.DefaultStmtFlags | types.FlagTruncateAsWarning) + require.NoError(t, sc.HandleError(err)) +} + +func BenchmarkErrCtx(b *testing.B) { + sc := stmtctx.NewStmtCtx() + + for i := 0; i < b.N; i++ { + sc.ErrCtx() + } +} +>>>>>>> 116456ddfb1 (sessionctx: refactor sessionctx pkg's warning and note generation (#49760)):pkg/sessionctx/stmtctx/stmtctx_test.go diff --git a/sessionctx/variable/noop.go b/sessionctx/variable/noop.go index 4c61a88c51820..0ac0199cf0c5e 100644 --- a/sessionctx/variable/noop.go +++ b/sessionctx/variable/noop.go @@ -16,6 +16,8 @@ package variable import ( "math" + + "github.com/pingcap/errors" ) // The following sysVars are noops. @@ -197,11 +199,11 @@ var noopSysVars = []*SysVar{ {Scope: ScopeGlobal | ScopeSession, Name: SQLAutoIsNull, Value: Off, Type: TypeBool, IsHintUpdatable: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { // checkSQLAutoIsNull requires TiDBEnableNoopFuncs != OFF for the same scope otherwise an error will be returned. // See also https://github.com/pingcap/tidb/issues/28230 - errMsg := ErrFunctionsNoopImpl.GenWithStackByArgs("sql_auto_is_null") + errMsg := ErrFunctionsNoopImpl.FastGenByArgs("sql_auto_is_null") if TiDBOptOn(normalizedValue) { if scope == ScopeSession && vars.NoopFuncsMode != OnInt { if vars.NoopFuncsMode == OffInt { - return Off, errMsg + return Off, errors.Trace(errMsg) } vars.StmtCtx.AppendWarning(errMsg) } @@ -211,7 +213,7 @@ var noopSysVars = []*SysVar{ return originalValue, errUnknownSystemVariable.GenWithStackByArgs(TiDBEnableNoopFuncs) } if val == Off { - return Off, errMsg + return Off, errors.Trace(errMsg) } if val == Warn { vars.StmtCtx.AppendWarning(errMsg) diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 2be92ac60ac07..97a25a8927f06 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -1672,9 +1672,9 @@ func (s *SessionVars) RaiseWarningWhenMPPEnforced(warning string) { return } if s.StmtCtx.InExplainStmt { - s.StmtCtx.AppendWarning(errors.New(warning)) + s.StmtCtx.AppendWarning(errors.NewNoStackError(warning)) } else { - s.StmtCtx.AppendExtraWarning(errors.New(warning)) + s.StmtCtx.AppendExtraWarning(errors.NewNoStackError(warning)) } } diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 835103bac9f2e..0ddc3ad58e839 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -959,7 +959,7 @@ var defaultSysVars = []*SysVar{ } } if intVal > 0 && intVal < 128 { // 128 Bytes - s.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(TiDBServerMemoryLimitSessMinSize, originalValue)) + s.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(TiDBServerMemoryLimitSessMinSize, originalValue)) intVal = 128 } return strconv.FormatUint(intVal, 10), nil @@ -1471,7 +1471,7 @@ var defaultSysVars = []*SysVar{ if mathutil.IntBits == 32 { if val, err := strconv.ParseUint(normalizedValue, 10, 64); err == nil { if val > uint64(math.MaxUint32) { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(GroupConcatMaxLen, originalValue)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(GroupConcatMaxLen, originalValue)) return strconv.FormatInt(int64(math.MaxUint32), 10), nil } } @@ -1508,7 +1508,7 @@ var defaultSysVars = []*SysVar{ } remainder := u % 1024 if remainder != 0 { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(MaxAllowedPacket, normalizedValue)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(MaxAllowedPacket, normalizedValue)) u -= remainder } return strconv.FormatUint(u, 10), nil @@ -1817,10 +1817,24 @@ var defaultSysVars = []*SysVar{ s.EnableVectorizedExpression = TiDBOptOn(val) return nil }}, +<<<<<<< HEAD:sessionctx/variable/sysvar.go {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableFastAnalyze, Value: BoolToOnOff(DefTiDBUseFastAnalyze), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { s.EnableFastAnalyze = TiDBOptOn(val) return nil }}, +======= + {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableFastAnalyze, Value: BoolToOnOff(DefTiDBUseFastAnalyze), Type: TypeBool, + Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { + if TiDBOptOn(normalizedValue) { + vars.StmtCtx.AppendWarning(errors.NewNoStackError("the fast analyze feature has already been removed in TiDB v7.5.0, so this will have no effect")) + } + return normalizedValue, nil + }, + SetSession: func(s *SessionVars, val string) error { + s.EnableFastAnalyze = TiDBOptOn(val) + return nil + }}, +>>>>>>> 116456ddfb1 (sessionctx: refactor sessionctx pkg's warning and note generation (#49760)):pkg/sessionctx/variable/sysvar.go {Scope: ScopeGlobal | ScopeSession, Name: TiDBSkipIsolationLevelCheck, Value: BoolToOnOff(DefTiDBSkipIsolationLevelCheck), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableRateLimitAction, Value: BoolToOnOff(DefTiDBEnableRateLimitAction), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { s.EnabledRateLimitAction = TiDBOptOn(val) @@ -1961,15 +1975,15 @@ var defaultSysVars = []*SysVar{ }, SetSession: func(s *SessionVars, val string) error { newMode := strings.ToLower(strings.TrimSpace(val)) if PartitionPruneMode(s.PartitionPruneMode.Load()) == Static && PartitionPruneMode(newMode) == Dynamic { - s.StmtCtx.AppendWarning(errors.New("Please analyze all partition tables again for consistency between partition and global stats")) - s.StmtCtx.AppendWarning(errors.New("Please avoid setting partition prune mode to dynamic at session level and set partition prune mode to dynamic at global level")) + s.StmtCtx.AppendWarning(errors.NewNoStackError("Please analyze all partition tables again for consistency between partition and global stats")) + s.StmtCtx.AppendWarning(errors.NewNoStackError("Please avoid setting partition prune mode to dynamic at session level and set partition prune mode to dynamic at global level")) } s.PartitionPruneMode.Store(newMode) return nil }, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { newMode := strings.ToLower(strings.TrimSpace(val)) if PartitionPruneMode(newMode) == Dynamic { - s.StmtCtx.AppendWarning(errors.New("Please analyze all partition tables again for consistency between partition and global stats")) + s.StmtCtx.AppendWarning(errors.NewNoStackError("Please analyze all partition tables again for consistency between partition and global stats")) } return nil }}, @@ -2033,7 +2047,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableExchangePartition, Value: On, Type: TypeBool, Validation: func(vars *SessionVars, s string, s2 string, flag ScopeFlag) (string, error) { if s == Off { - vars.StmtCtx.AppendWarning(errors.New("tidb_enable_exchange_partition is always turned on. This variable has been deprecated and will be removed in the future releases")) + vars.StmtCtx.AppendWarning(errors.NewNoStackError("tidb_enable_exchange_partition is always turned on. This variable has been deprecated and will be removed in the future releases")) } return On, nil }, @@ -2152,7 +2166,7 @@ var defaultSysVars = []*SysVar{ }, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { intVal := TidbOptInt64(normalizedValue, DefTiDBMemQuotaQuery) if intVal > 0 && intVal < 128 { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(TiDBMemQuotaQuery, originalValue)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(TiDBMemQuotaQuery, originalValue)) normalizedValue = "128" } return normalizedValue, nil @@ -2235,7 +2249,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableTiFlashReadForWriteStmt, Value: On, Type: TypeBool, Validation: func(vars *SessionVars, s string, s2 string, flag ScopeFlag) (string, error) { if s == Off { - vars.StmtCtx.AppendWarning(errors.New("tidb_enable_tiflash_read_for_write_stmt is always turned on. This variable has been deprecated and will be removed in the future releases")) + vars.StmtCtx.AppendWarning(errors.NewNoStackError("tidb_enable_tiflash_read_for_write_stmt is always turned on. This variable has been deprecated and will be removed in the future releases")) } return On, nil }, @@ -2501,6 +2515,7 @@ var defaultSysVars = []*SysVar{ s.OptOrderingIdxSelThresh = tidbOptFloat64(val, DefTiDBOptOrderingIdxSelThresh) return nil }}, +<<<<<<< HEAD:sessionctx/variable/sysvar.go {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptFixControl, Value: "", Type: TypeStr, IsHintUpdatable: true, SetSession: func(s *SessionVars, val string) error { newMap := make(map[uint64]string) @@ -2524,6 +2539,32 @@ var defaultSysVars = []*SysVar{ errors.Errorf("found repeated fix control: %d:%s is overwritten with %s", num, originalV, v)) } newMap[num] = v +======= + {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptEnableMPPSharedCTEExecution, Value: BoolToOnOff(DefTiDBOptEnableMPPSharedCTEExecution), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { + s.EnableMPPSharedCTEExecution = TiDBOptOn(val) + return nil + }}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptFixControl, Value: "", Type: TypeStr, IsHintUpdatableVerfied: true, + SetGlobal: func(ctx context.Context, vars *SessionVars, val string) error { + // validation logic for setting global + // we don't put this in Validation to avoid repeating the checking logic for setting session. + _, warnings, err := fixcontrol.ParseToMap(val) + if err != nil { + return err + } + for _, warning := range warnings { + vars.StmtCtx.AppendWarning(errors.NewNoStackError(warning)) + } + return nil + }, + SetSession: func(s *SessionVars, val string) error { + newMap, warnings, err := fixcontrol.ParseToMap(val) + if err != nil { + return err + } + for _, warning := range warnings { + s.StmtCtx.AppendWarning(errors.NewNoStackError(warning)) +>>>>>>> 116456ddfb1 (sessionctx: refactor sessionctx pkg's warning and note generation (#49760)):pkg/sessionctx/variable/sysvar.go } s.OptimizerFixControl = newMap return nil @@ -2704,6 +2745,82 @@ var defaultSysVars = []*SysVar{ return nil }, }, +<<<<<<< HEAD:sessionctx/variable/sysvar.go +======= + {Scope: ScopeGlobal, Name: TiDBEnableCheckConstraint, Value: BoolToOnOff(DefTiDBEnableCheckConstraint), Type: TypeBool, SetGlobal: func(ctx context.Context, vars *SessionVars, s string) error { + EnableCheckConstraint.Store(TiDBOptOn(s)) + return nil + }, GetGlobal: func(ctx context.Context, vars *SessionVars) (string, error) { + return BoolToOnOff(EnableCheckConstraint.Load()), nil + }}, + {Scope: ScopeSession, Name: TiDBSessionAlias, Value: "", Type: TypeStr, + Validation: func(s *SessionVars, normalizedValue string, originalValue string, _ ScopeFlag) (string, error) { + chars := []rune(normalizedValue) + warningAdded := false + if len(chars) > 64 { + s.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(TiDBSessionAlias, originalValue)) + warningAdded = true + chars = chars[:64] + normalizedValue = string(chars) + } + + // truncate to a valid identifier + for normalizedValue != "" && util.IsInCorrectIdentifierName(normalizedValue) { + if !warningAdded { + s.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(TiDBSessionAlias, originalValue)) + warningAdded = true + } + chars = chars[:len(chars)-1] + normalizedValue = string(chars) + } + + return normalizedValue, nil + }, + SetSession: func(vars *SessionVars, s string) error { + vars.SessionAlias = s + return nil + }, GetSession: func(vars *SessionVars) (string, error) { + return vars.SessionAlias, nil + }}, + { + Scope: ScopeGlobal | ScopeSession, + Name: TiDBOptObjective, + Value: DefTiDBOptObjective, + Type: TypeEnum, + PossibleValues: []string{OptObjectiveModerate, OptObjectiveDeterminate}, + SetSession: func(vars *SessionVars, s string) error { + vars.OptObjective = s + return nil + }, + }, + {Scope: ScopeInstance, Name: TiDBServiceScope, Value: "", Type: TypeStr, + Validation: func(_ *SessionVars, normalizedValue string, originalValue string, _ ScopeFlag) (string, error) { + _, ok := distroleutil.ToTiDBServiceScope(originalValue) + if !ok { + err := fmt.Errorf("incorrect value: `%s`. %s options: %s", + originalValue, + TiDBServiceScope, `"", background`) + return normalizedValue, err + } + return normalizedValue, nil + }, + SetGlobal: func(ctx context.Context, vars *SessionVars, s string) error { + ServiceScope.Store(strings.ToLower(s)) + return nil + }, GetGlobal: func(ctx context.Context, vars *SessionVars) (string, error) { + return ServiceScope.Load(), nil + }}, + {Scope: ScopeGlobal, Name: TiDBSchemaVersionCacheLimit, Value: strconv.Itoa(DefTiDBSchemaVersionCacheLimit), Type: TypeInt, MinValue: 2, MaxValue: math.MaxUint8, AllowEmpty: true, + SetGlobal: func(_ context.Context, s *SessionVars, val string) error { + SchemaVersionCacheLimit.Store(TidbOptInt64(val, DefTiDBSchemaVersionCacheLimit)) + return nil + }}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBIdleTransactionTimeout, Value: strconv.Itoa(DefTiDBIdleTransactionTimeout), Type: TypeUnsigned, MinValue: 0, MaxValue: secondsPerYear, + SetSession: func(s *SessionVars, val string) error { + s.IdleTransactionTimeout = tidbOptPositiveInt32(val, DefTiDBIdleTransactionTimeout) + return nil + }}, +>>>>>>> 116456ddfb1 (sessionctx: refactor sessionctx pkg's warning and note generation (#49760)):pkg/sessionctx/variable/sysvar.go } func setTiFlashComputeDispatchPolicy(s *SessionVars, val string) error { diff --git a/sessionctx/variable/variable.go b/sessionctx/variable/variable.go index 48eb86a45c2a2..5d65ca0257de0 100644 --- a/sessionctx/variable/variable.go +++ b/sessionctx/variable/variable.go @@ -397,11 +397,11 @@ func (sv *SysVar) checkDurationSystemVar(value string, vars *SessionVars) (strin } // Check for min/max violations if int64(d) < sv.MinValue { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return time.Duration(sv.MinValue).String(), nil } if uint64(d) > sv.MaxValue { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return time.Duration(sv.MaxValue).String(), nil } // return a string representation of the duration @@ -420,7 +420,7 @@ func (sv *SysVar) checkUInt64SystemVar(value string, vars *SessionVars) (string, if err != nil { return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name) } - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return strconv.FormatInt(sv.MinValue, 10), nil } val, err := strconv.ParseUint(value, 10, 64) @@ -428,11 +428,11 @@ func (sv *SysVar) checkUInt64SystemVar(value string, vars *SessionVars) (string, return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name) } if val < uint64(sv.MinValue) { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return strconv.FormatInt(sv.MinValue, 10), nil } if val > sv.MaxValue { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return strconv.FormatUint(sv.MaxValue, 10), nil } return value, nil @@ -447,11 +447,11 @@ func (sv *SysVar) checkInt64SystemVar(value string, vars *SessionVars) (string, return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name) } if val < sv.MinValue { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return strconv.FormatInt(sv.MinValue, 10), nil } if val > int64(sv.MaxValue) { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return strconv.FormatUint(sv.MaxValue, 10), nil } return value, nil @@ -479,11 +479,11 @@ func (sv *SysVar) checkFloatSystemVar(value string, vars *SessionVars) (string, return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name) } if val < float64(sv.MinValue) { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return strconv.FormatInt(sv.MinValue, 10), nil } if val > float64(sv.MaxValue) { - vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value)) + vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(sv.Name, value)) return strconv.FormatUint(sv.MaxValue, 10), nil } return value, nil diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index d7eda1a16c691..91ec04de9c428 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -126,7 +126,7 @@ func checkCollation(vars *SessionVars, normalizedValue string, originalValue str func checkCharacterSet(normalizedValue string, argName string) (string, error) { if normalizedValue == "" { - return normalizedValue, errors.Trace(ErrWrongValueForVar.GenWithStackByArgs(argName, "NULL")) + return normalizedValue, errors.Trace(ErrWrongValueForVar.FastGenByArgs(argName, "NULL")) } cs, err := charset.GetCharsetInfo(normalizedValue) if err != nil { @@ -137,14 +137,14 @@ func checkCharacterSet(normalizedValue string, argName string) (string, error) { // checkReadOnly requires TiDBEnableNoopFuncs=1 for the same scope otherwise an error will be returned. func checkReadOnly(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag, offlineMode bool) (string, error) { - errMsg := ErrFunctionsNoopImpl.GenWithStackByArgs("READ ONLY") + errMsg := ErrFunctionsNoopImpl.FastGenByArgs("READ ONLY") if offlineMode { - errMsg = ErrFunctionsNoopImpl.GenWithStackByArgs("OFFLINE MODE") + errMsg = ErrFunctionsNoopImpl.FastGenByArgs("OFFLINE MODE") } if TiDBOptOn(normalizedValue) { if scope == ScopeSession && vars.NoopFuncsMode != OnInt { if vars.NoopFuncsMode == OffInt { - return Off, errMsg + return Off, errors.Trace(errMsg) } vars.StmtCtx.AppendWarning(errMsg) } @@ -154,7 +154,7 @@ func checkReadOnly(vars *SessionVars, normalizedValue string, originalValue stri return originalValue, errUnknownSystemVariable.GenWithStackByArgs(TiDBEnableNoopFuncs) } if val == Off { - return Off, errMsg + return Off, errors.Trace(errMsg) } if val == Warn { vars.StmtCtx.AppendWarning(errMsg) @@ -166,7 +166,7 @@ func checkReadOnly(vars *SessionVars, normalizedValue string, originalValue stri func checkIsolationLevel(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { if normalizedValue == "SERIALIZABLE" || normalizedValue == "READ-UNCOMMITTED" { - returnErr := ErrUnsupportedIsolationLevel.GenWithStackByArgs(normalizedValue) + returnErr := ErrUnsupportedIsolationLevel.FastGenByArgs(normalizedValue) if !TiDBOptOn(vars.systems[TiDBSkipIsolationLevelCheck]) { return normalizedValue, ErrUnsupportedIsolationLevel.GenWithStackByArgs(normalizedValue) } @@ -388,7 +388,7 @@ func parseTimeZone(s string) (*time.Location, error) { func parseMemoryLimit(s *SessionVars, normalizedValue string, originalValue string) (byteSize uint64, normalizedStr string, err error) { defer func() { if err == nil && byteSize > 0 && byteSize < (512<<20) { - s.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(TiDBServerMemoryLimit, originalValue)) + s.StmtCtx.AppendWarning(ErrTruncatedWrongValue.FastGenByArgs(TiDBServerMemoryLimit, originalValue)) byteSize = 512 << 20 normalizedStr = "512MB" }