diff --git a/pkg/executor/aggfuncs/func_group_concat.go b/pkg/executor/aggfuncs/func_group_concat.go index f036f100ba432..51228caf4688a 100644 --- a/pkg/executor/aggfuncs/func_group_concat.go +++ b/pkg/executor/aggfuncs/func_group_concat.go @@ -75,7 +75,7 @@ func (e *baseGroupConcat4String) handleTruncateError(sctx sessionctx.Context) (e if !sctx.GetSessionVars().StmtCtx.TypeFlags().TruncateAsWarning() { return expression.ErrCutValueGroupConcat.GenWithStackByArgs(e.args[0].String()) } - sctx.GetSessionVars().StmtCtx.AppendWarning(expression.ErrCutValueGroupConcat.GenWithStackByArgs(e.args[0].String())) + sctx.GetSessionVars().StmtCtx.AppendWarning(expression.ErrCutValueGroupConcat.FastGenByArgs(e.args[0].String())) } return nil } diff --git a/pkg/executor/analyze.go b/pkg/executor/analyze.go index ebaf7bfc3aa15..7ff94220ca474 100644 --- a/pkg/executor/analyze.go +++ b/pkg/executor/analyze.go @@ -292,7 +292,7 @@ func warnLockedTableMsg(sessionVars *variable.SessionVars, needAnalyzeTableCnt u } else { msg = "skip analyze locked table: %s" } - sessionVars.StmtCtx.AppendWarning(errors.Errorf(msg, tables)) + sessionVars.StmtCtx.AppendWarning(errors.NewNoStackErrorf(msg, tables)) } } diff --git a/pkg/executor/bind.go b/pkg/executor/bind.go index 92cf8d89e737b..04e7d51864257 100644 --- a/pkg/executor/bind.go +++ b/pkg/executor/bind.go @@ -117,7 +117,7 @@ func (e *SQLBindExec) setBindingStatus() error { } ok, err := domain.GetDomain(e.Ctx()).BindHandle().SetGlobalBindingStatus(e.normdOrigSQL, bindInfo, e.newStatus) if err == nil && !ok { - warningMess := errors.New("There are no bindings can be set the status. Please check the SQL text") + warningMess := errors.NewNoStackError("There are no bindings can be set the status. Please check the SQL text") e.Ctx().GetSessionVars().StmtCtx.AppendWarning(warningMess) } return err @@ -126,7 +126,7 @@ func (e *SQLBindExec) setBindingStatus() error { func (e *SQLBindExec) setBindingStatusByDigest() error { ok, err := domain.GetDomain(e.Ctx()).BindHandle().SetGlobalBindingStatusByDigest(e.newStatus, e.sqlDigest) if err == nil && !ok { - warningMess := errors.New("There are no bindings can be set the status. Please check the SQL text") + warningMess := errors.NewNoStackError("There are no bindings can be set the status. Please check the SQL text") e.Ctx().GetSessionVars().StmtCtx.AppendWarning(warningMess) } return err diff --git a/pkg/executor/builder.go b/pkg/executor/builder.go index d5b5b7ad35d97..521099206c0ef 100644 --- a/pkg/executor/builder.go +++ b/pkg/executor/builder.go @@ -2651,7 +2651,7 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown( if *sampleRate < 0 { *sampleRate, sampleRateReason = b.getAdjustedSampleRate(task) if task.PartitionName != "" { - sc.AppendNote(errors.Errorf( + sc.AppendNote(errors.NewNoStackErrorf( `Analyze use auto adjusted sample rate %f for table %s.%s's partition %s, reason to use this rate is "%s"`, *sampleRate, task.DBName, @@ -2660,7 +2660,7 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown( sampleRateReason, )) } else { - sc.AppendNote(errors.Errorf( + sc.AppendNote(errors.NewNoStackErrorf( `Analyze use auto adjusted sample rate %f for table %s.%s, reason to use this rate is "%s"`, *sampleRate, task.DBName, @@ -3409,7 +3409,7 @@ func (b *executorBuilder) buildTableReader(v *plannercore.PhysicalTableReader) e useTiFlash := useMPP || useTiFlashBatchCop if useTiFlash { if _, isTiDBZoneLabelSet := config.GetGlobalConfig().Labels[placement.DCLabelKey]; b.ctx.GetSessionVars().TiFlashReplicaRead != tiflash.AllReplicas && !isTiDBZoneLabelSet { - b.ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf("the variable tiflash_replica_read is ignored, because the entry TiDB[%s] does not set the zone attribute and tiflash_replica_read is '%s'", config.GetGlobalConfig().AdvertiseAddress, tiflash.GetTiFlashReplicaRead(b.ctx.GetSessionVars().TiFlashReplicaRead))) + b.ctx.GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackErrorf("the variable tiflash_replica_read is ignored, because the entry TiDB[%s] does not set the zone attribute and tiflash_replica_read is '%s'", config.GetGlobalConfig().AdvertiseAddress, tiflash.GetTiFlashReplicaRead(b.ctx.GetSessionVars().TiFlashReplicaRead))) } } if useMPP { diff --git a/pkg/executor/compact_table.go b/pkg/executor/compact_table.go index 966d5ca8265b1..110d03b54a4b2 100644 --- a/pkg/executor/compact_table.go +++ b/pkg/executor/compact_table.go @@ -87,7 +87,7 @@ func (e *CompactTableTiFlashExec) Next(ctx context.Context, chk *chunk.Chunk) er func (e *CompactTableTiFlashExec) doCompact(execCtx context.Context) error { vars := e.Ctx().GetSessionVars() if e.tableInfo.TiFlashReplica == nil || e.tableInfo.TiFlashReplica.Count == 0 { - vars.StmtCtx.AppendWarning(errors.Errorf("compact skipped: no tiflash replica in the table")) + vars.StmtCtx.AppendWarning(errors.NewNoStackErrorf("compact skipped: no tiflash replica in the table")) return nil } @@ -257,33 +257,38 @@ func (task *storeCompactTask) compactOnePhysicalTable(physicalTableID int64) (bo if err != nil { // Even after backoff, the request is still failed.., or the request is cancelled or timed out // For example, the store is down. Let's simply don't compact other partitions. - warn := errors.Errorf("compact on store %s failed: %v", task.targetStore.Address, err) + warn := errors.NewNoStackErrorf("compact on store %s failed: %v", task.targetStore.Address, err) task.parentExec.Ctx().GetSessionVars().StmtCtx.AppendWarning(warn) + newErr := errors.Trace(warn) task.logFailure( zap.Int64("physical-table-id", physicalTableID), zap.Error(err)) - return false, warn + return false, newErr } if resp.GetError() != nil { switch resp.GetError().GetError().(type) { case *kvrpcpb.CompactError_ErrCompactInProgress: - warn := errors.Errorf("compact on store %s failed: table is compacting in progress", task.targetStore.Address) + // warn is light stackless. + warn := errors.NewNoStackErrorf("compact on store %s failed: table is compacting in progress", task.targetStore.Address) task.parentExec.Ctx().GetSessionVars().StmtCtx.AppendWarning(warn) + err := errors.Trace(warn) task.logFailure( zap.Int64("physical-table-id", physicalTableID), - zap.Error(warn)) + zap.Error(err)) // TiFlash reported that there are existing compacting for the same table. // We should stop the whole SQL execution, including compacting requests to other stores, as repeatedly // compacting the same table is a waste of resource. - return true, warn + return true, err case *kvrpcpb.CompactError_ErrTooManyPendingTasks: // The store is already very busy, don't retry and don't compact other partitions. - warn := errors.Errorf("compact on store %s failed: store is too busy", task.targetStore.Address) + // warn is light stackless. + warn := errors.NewNoStackErrorf("compact on store %s failed: store is too busy", task.targetStore.Address) task.parentExec.Ctx().GetSessionVars().StmtCtx.AppendWarning(warn) + err := errors.Trace(warn) task.logFailure( zap.Int64("physical-table-id", physicalTableID), - zap.Error(warn)) - return false, warn + zap.Error(err)) + return false, err case *kvrpcpb.CompactError_ErrPhysicalTableNotExist: // The physical table does not exist, don't retry this partition, but other partitions should still be compacted. // This may happen when partition or table is dropped during the long compaction. @@ -296,12 +301,13 @@ func (task *storeCompactTask) compactOnePhysicalTable(physicalTableID int64) (bo return false, nil default: // Others are unexpected errors, don't retry and don't compact other partitions. - warn := errors.Errorf("compact on store %s failed: internal error (check logs for details)", task.targetStore.Address) + warn := errors.NewNoStackErrorf("compact on store %s failed: internal error (check logs for details)", task.targetStore.Address) task.parentExec.Ctx().GetSessionVars().StmtCtx.AppendWarning(warn) + err := errors.Trace(warn) task.logFailure( zap.Int64("physical-table-id", physicalTableID), zap.Any("response-error", resp.GetError().GetError())) - return false, warn + return false, err } } @@ -314,14 +320,15 @@ func (task *storeCompactTask) compactOnePhysicalTable(physicalTableID int64) (bo if len(lastEndKey) == 0 || bytes.Compare(lastEndKey, startKey) <= 0 { // The TiFlash server returned an invalid compacted end key. // This is unexpected... - warn := errors.Errorf("compact on store %s failed: internal error (check logs for details)", task.targetStore.Address) + warn := errors.NewNoStackErrorf("compact on store %s failed: internal error (check logs for details)", task.targetStore.Address) task.parentExec.Ctx().GetSessionVars().StmtCtx.AppendWarning(warn) + err := errors.Trace(warn) task.logFailure( zap.Int64("physical-table-id", physicalTableID), zap.String("compacted-start-key", hex.EncodeToString(resp.GetCompactedStartKey())), zap.String("compacted-end-key", hex.EncodeToString(resp.GetCompactedEndKey())), ) - return false, warn + return false, err } startKey = lastEndKey } diff --git a/pkg/executor/ddl.go b/pkg/executor/ddl.go index 6766742fbdab5..e88367878f241 100644 --- a/pkg/executor/ddl.go +++ b/pkg/executor/ddl.go @@ -119,12 +119,14 @@ func (e *DDLExec) Next(ctx context.Context, _ *chunk.Chunk) (err error) { for _, tn := range s.Tables { nonExistsTables = append(nonExistsTables, ast.Ident{Schema: tn.Schema, Name: tn.Name}.String()) } - err = infoschema.ErrTableDropExists.GenWithStackByArgs(strings.Join(nonExistsTables, ",")) + // stackless err once used like note. + err = infoschema.ErrTableDropExists.FastGenByArgs(strings.Join(nonExistsTables, ",")) if s.IfExists { e.Ctx().GetSessionVars().StmtCtx.AppendNote(err) return nil } - return err + // complete and trace stack info. + return errors.Trace(err) } // if all tables are local temporary, directly drop those tables. @@ -275,12 +277,12 @@ func (e *DDLExec) createSessionTemporaryTable(s *ast.CreateTableStmt) error { _, exists := e.getLocalTemporaryTable(s.Table.Schema, s.Table.Name) if exists { - err := infoschema.ErrTableExists.GenWithStackByArgs(ast.Ident{Schema: s.Table.Schema, Name: s.Table.Name}) + err := infoschema.ErrTableExists.FastGenByArgs(ast.Ident{Schema: s.Table.Schema, Name: s.Table.Name}) if s.IfNotExists { e.Ctx().GetSessionVars().StmtCtx.AppendNote(err) return nil } - return err + return errors.Trace(err) } tbInfo, err := ddl.BuildSessionTemporaryTableInfo(e.Ctx(), is, s, dbInfo.Charset, dbInfo.Collate, dbInfo.PlacementPolicyRef) @@ -696,7 +698,7 @@ func (e *DDLExec) getRecoverDBByName(schemaName model.CIStr) (recoverSchemaInfo func (e *DDLExec) executeLockTables(s *ast.LockTablesStmt) error { if !config.TableLockEnabled() { - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(exeerrors.ErrFuncNotEnabled.GenWithStackByArgs("LOCK TABLES", "enable-table-lock")) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(exeerrors.ErrFuncNotEnabled.FastGenByArgs("LOCK TABLES", "enable-table-lock")) return nil } @@ -711,7 +713,7 @@ func (e *DDLExec) executeLockTables(s *ast.LockTablesStmt) error { func (e *DDLExec) executeUnlockTables(_ *ast.UnlockTablesStmt) error { if !config.TableLockEnabled() { - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(exeerrors.ErrFuncNotEnabled.GenWithStackByArgs("UNLOCK TABLES", "enable-table-lock")) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(exeerrors.ErrFuncNotEnabled.FastGenByArgs("UNLOCK TABLES", "enable-table-lock")) return nil } lockedTables := e.Ctx().GetAllTableLocks() diff --git a/pkg/executor/lockstats/lock_stats_executor.go b/pkg/executor/lockstats/lock_stats_executor.go index 2a59ee41fdb80..59b3108afc3f2 100644 --- a/pkg/executor/lockstats/lock_stats_executor.go +++ b/pkg/executor/lockstats/lock_stats_executor.go @@ -65,7 +65,7 @@ func (e *LockExec) Next(_ context.Context, _ *chunk.Chunk) error { return err } if msg != "" { - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.New(msg)) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackError(msg)) } } else { tableWithPartitions, err := populateTableAndPartitionIDs(e.Tables, is) @@ -78,7 +78,7 @@ func (e *LockExec) Next(_ context.Context, _ *chunk.Chunk) error { return err } if msg != "" { - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.New(msg)) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackError(msg)) } } diff --git a/pkg/executor/lockstats/unlock_stats_executor.go b/pkg/executor/lockstats/unlock_stats_executor.go index 499745ef65e75..2e339ef4327ff 100644 --- a/pkg/executor/lockstats/unlock_stats_executor.go +++ b/pkg/executor/lockstats/unlock_stats_executor.go @@ -60,7 +60,7 @@ func (e *UnlockExec) Next(context.Context, *chunk.Chunk) error { return err } if msg != "" { - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.New(msg)) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackError(msg)) } } else { tableWithPartitions, err := populateTableAndPartitionIDs(e.Tables, is) @@ -72,7 +72,7 @@ func (e *UnlockExec) Next(context.Context, *chunk.Chunk) error { return err } if msg != "" { - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.New(msg)) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackError(msg)) } } diff --git a/pkg/executor/memtable_reader.go b/pkg/executor/memtable_reader.go index 2093a8c137be3..3406d8ab2766f 100644 --- a/pkg/executor/memtable_reader.go +++ b/pkg/executor/memtable_reader.go @@ -188,7 +188,7 @@ func fetchClusterConfig(sctx sessionctx.Context, nodeTypes, nodeAddrs set.String address := srv.Address statusAddr := srv.StatusAddr if len(statusAddr) == 0 { - sctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf("%s node %s does not contain status address", typ, address)) + sctx.GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackErrorf("%s node %s does not contain status address", typ, address)) continue } wg.Add(1) @@ -456,7 +456,7 @@ func (e *clusterLogRetriever) startRetrieving( address := srv.Address statusAddr := srv.StatusAddr if len(statusAddr) == 0 { - sctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf("%s node %s does not contain status address", typ, address)) + sctx.GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackErrorf("%s node %s does not contain status address", typ, address)) continue } ch := make(chan logStreamResult) diff --git a/pkg/executor/plan_replayer.go b/pkg/executor/plan_replayer.go index 7ae5bbb571f8a..771a3baf9f47a 100644 --- a/pkg/executor/plan_replayer.go +++ b/pkg/executor/plan_replayer.go @@ -401,7 +401,7 @@ func loadVariables(ctx sessionctx.Context, z *zip.Reader) error { } } if len(unLoadVars) > 0 { - ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf("variables set failed:%s", strings.Join(unLoadVars, ","))) + ctx.GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackErrorf("variables set failed:%s", strings.Join(unLoadVars, ","))) } return nil } diff --git a/pkg/executor/revoke.go b/pkg/executor/revoke.go index dbeba1320987e..21dca529c6b97 100644 --- a/pkg/executor/revoke.go +++ b/pkg/executor/revoke.go @@ -203,7 +203,7 @@ func (e *RevokeExec) revokePriv(internalSession sessionctx.Context, priv *ast.Pr func (e *RevokeExec) revokeDynamicPriv(internalSession sessionctx.Context, privName string, user, host string) error { privName = strings.ToUpper(privName) if !privilege.GetPrivilegeManager(e.Ctx()).IsDynamicPrivilege(privName) { // for MySQL compatibility - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(exeerrors.ErrDynamicPrivilegeNotRegistered.GenWithStackByArgs(privName)) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(exeerrors.ErrDynamicPrivilegeNotRegistered.FastGenByArgs(privName)) } ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnPrivilege) _, err := internalSession.(sqlexec.SQLExecutor).ExecuteInternal(ctx, "DELETE FROM mysql.global_grants WHERE user = %? AND host = %? AND priv = %?", user, host, privName) diff --git a/pkg/executor/set.go b/pkg/executor/set.go index 5da9432610ad8..4d80c4695adef 100644 --- a/pkg/executor/set.go +++ b/pkg/executor/set.go @@ -138,13 +138,13 @@ func (e *SetExecutor) setSysVariable(ctx context.Context, name string, v *expres // The variable is a noop. For compatibility we allow it to still // be changed, but we append a warning since users might be expecting // something that's not going to happen. - sessionVars.StmtCtx.AppendWarning(exeerrors.ErrSettingNoopVariable.GenWithStackByArgs(sysVar.Name)) + sessionVars.StmtCtx.AppendWarning(exeerrors.ErrSettingNoopVariable.FastGenByArgs(sysVar.Name)) } if sysVar.HasInstanceScope() && !v.IsGlobal && sessionVars.EnableLegacyInstanceScope { // For backward compatibility we will change the v.IsGlobal to true, // and append a warning saying this will not be supported in future. v.IsGlobal = true - sessionVars.StmtCtx.AppendWarning(exeerrors.ErrInstanceScope.GenWithStackByArgs(sysVar.Name)) + sessionVars.StmtCtx.AppendWarning(exeerrors.ErrInstanceScope.FastGenByArgs(sysVar.Name)) } if v.IsGlobal { diff --git a/pkg/executor/simple.go b/pkg/executor/simple.go index 8715d9d14f23b..028b9403fb6a9 100644 --- a/pkg/executor/simple.go +++ b/pkg/executor/simple.go @@ -615,9 +615,9 @@ func (e *SimpleExec) executeBegin(ctx context.Context, s *ast.BeginStmt) error { if s.ReadOnly { noopFuncsMode := e.Ctx().GetSessionVars().NoopFuncsMode if s.AsOf == nil && noopFuncsMode != variable.OnInt { - err := expression.ErrFunctionsNoopImpl.GenWithStackByArgs("READ ONLY") + err := expression.ErrFunctionsNoopImpl.FastGenByArgs("READ ONLY") if noopFuncsMode == variable.OffInt { - return err + return errors.Trace(err) } e.Ctx().GetSessionVars().StmtCtx.AppendWarning(err) } @@ -1144,7 +1144,7 @@ func (e *SimpleExec) executeCreateUser(ctx context.Context, s *ast.CreateUserStm } return exeerrors.ErrCannotUser.GenWithStackByArgs("CREATE USER", user) } - err := infoschema.ErrUserAlreadyExists.GenWithStackByArgs(user) + err := infoschema.ErrUserAlreadyExists.FastGenByArgs(user) e.Ctx().GetSessionVars().StmtCtx.AppendNote(err) continue } @@ -1916,7 +1916,7 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt) switch authTokenOptionHandler { case noNeedAuthTokenOptions: if len(authTokenOptions) > 0 { - err := errors.New("TOKEN_ISSUER is not needed for the auth plugin") + err := errors.NewNoStackError("TOKEN_ISSUER is not needed for the auth plugin") e.Ctx().GetSessionVars().StmtCtx.AppendWarning(err) } case OptionalAuthTokenOptions: @@ -1931,7 +1931,7 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt) fields = append(fields, alterField{authTokenOption.Type.String() + "=%?", authTokenOption.Value}) } } else { - err := errors.New("Auth plugin 'tidb_auth_plugin' needs TOKEN_ISSUER") + err := errors.NewNoStackError("Auth plugin 'tidb_auth_plugin' needs TOKEN_ISSUER") e.Ctx().GetSessionVars().StmtCtx.AppendWarning(err) } } @@ -1978,7 +1978,7 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt) return exeerrors.ErrCannotUser.GenWithStackByArgs("ALTER USER", strings.Join(failedUsers, ",")) } for _, user := range failedUsers { - err := infoschema.ErrUserDropExists.GenWithStackByArgs(user) + err := infoschema.ErrUserDropExists.FastGenByArgs(user) e.Ctx().GetSessionVars().StmtCtx.AppendNote(err) } } @@ -2239,7 +2239,7 @@ func (e *SimpleExec) executeDropUser(ctx context.Context, s *ast.DropUserStmt) e failedUsers = append(failedUsers, user.String()) break } - e.Ctx().GetSessionVars().StmtCtx.AppendNote(infoschema.ErrUserDropExists.GenWithStackByArgs(user)) + e.Ctx().GetSessionVars().StmtCtx.AppendNote(infoschema.ErrUserDropExists.FastGenByArgs(user)) } // Certain users require additional privileges in order to be modified. @@ -2474,7 +2474,7 @@ func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error case mysql.AuthCachingSha2Password, mysql.AuthTiDBSM3Password: pwd = auth.NewHashPassword(s.Password, authplugin) case mysql.AuthSocket: - e.Ctx().GetSessionVars().StmtCtx.AppendNote(exeerrors.ErrSetPasswordAuthPlugin.GenWithStackByArgs(u, h)) + e.Ctx().GetSessionVars().StmtCtx.AppendNote(exeerrors.ErrSetPasswordAuthPlugin.FastGenByArgs(u, h)) pwd = "" default: pwd = auth.EncodePassword(s.Password) @@ -2541,7 +2541,7 @@ func (e *SimpleExec) executeKillStmt(ctx context.Context, s *ast.KillStmt) error } sm.Kill(s.ConnectionID, s.Query, false) } else { - err := errors.New("Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] [connectionID | CONNECTION_ID()]' instead") + err := errors.NewNoStackError("Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] [connectionID | CONNECTION_ID()]' instead") e.Ctx().GetSessionVars().StmtCtx.AppendWarning(err) } return nil @@ -2560,7 +2560,7 @@ func (e *SimpleExec) executeKillStmt(ctx context.Context, s *ast.KillStmt) error gcid, isTruncated, err := globalconn.ParseConnID(s.ConnectionID) if err != nil { - err1 := errors.New("Parse ConnectionID failed: " + err.Error()) + err1 := errors.NewNoStackError("Parse ConnectionID failed: " + err.Error()) e.Ctx().GetSessionVars().StmtCtx.AppendWarning(err1) return nil } @@ -2569,14 +2569,14 @@ func (e *SimpleExec) executeKillStmt(ctx context.Context, s *ast.KillStmt) error logutil.BgLogger().Warn(message, zap.Uint64("conn", s.ConnectionID)) // Notice that this warning cannot be seen if KILL is triggered by "CTRL-C" of mysql client, // as the KILL is sent by a new connection. - err := errors.New(message) + err := errors.NewNoStackError(message) e.Ctx().GetSessionVars().StmtCtx.AppendWarning(err) return nil } if gcid.ServerID != sm.ServerID() { if err := killRemoteConn(ctx, e.Ctx(), &gcid, s.Query); err != nil { - err1 := errors.New("KILL remote connection failed: " + err.Error()) + err1 := errors.NewNoStackError("KILL remote connection failed: " + err.Error()) e.Ctx().GetSessionVars().StmtCtx.AppendWarning(err1) } } else { @@ -2811,7 +2811,7 @@ func (e *SimpleExec) executeAdminFlushPlanCache(s *ast.AdminStmt) error { return errors.New("Do not support the 'admin flush global scope.'") } if !e.Ctx().GetSessionVars().EnablePreparedPlanCache { - e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.New("The plan cache is disable. So there no need to flush the plan cache")) + e.Ctx().GetSessionVars().StmtCtx.AppendWarning(errors.NewNoStackError("The plan cache is disable. So there no need to flush the plan cache")) return nil } now := types.NewTime(types.FromGoTime(time.Now().In(e.Ctx().GetSessionVars().StmtCtx.TimeZone())), mysql.TypeTimestamp, 3) diff --git a/pkg/expression/simple_rewriter.go b/pkg/expression/simple_rewriter.go index f19c0f021278d..ce4b6dcd0fcfa 100644 --- a/pkg/expression/simple_rewriter.go +++ b/pkg/expression/simple_rewriter.go @@ -94,7 +94,7 @@ func ParseSimpleExprsWithNames(ctx sessionctx.Context, exprStr string, schema *S stmts, warns, err = parser.New().ParseSQL(exprStr) } if err != nil { - return nil, util.SyntaxWarn(err) + return nil, errors.Trace(util.SyntaxWarn(err)) } for _, warn := range warns { ctx.GetSessionVars().StmtCtx.AppendWarning(util.SyntaxWarn(warn)) diff --git a/pkg/table/tables/partition.go b/pkg/table/tables/partition.go index dc036ba94f1a3..26b0f3b098ee5 100644 --- a/pkg/table/tables/partition.go +++ b/pkg/table/tables/partition.go @@ -1862,7 +1862,8 @@ func parseExpr(p *parser.Parser, exprStr string) (ast.ExprNode, error) { exprStr = "select " + exprStr stmts, _, err := p.ParseSQL(exprStr) if err != nil { - return nil, util.SyntaxWarn(err) + // if you want to use warn like an error, trace the stack info by yourself. + return nil, errors.Trace(util.SyntaxWarn(err)) } fields := stmts[0].(*ast.SelectStmt).Fields.Fields return fields[0].Expr, nil diff --git a/pkg/util/misc.go b/pkg/util/misc.go index 1b0fce47d2b64..73025d5feac96 100644 --- a/pkg/util/misc.go +++ b/pkg/util/misc.go @@ -174,7 +174,7 @@ func SyntaxWarn(err error) error { } } - return parser.ErrParse.GenWithStackByArgs(syntaxErrorPrefix, err.Error()) + return parser.ErrParse.FastGenByArgs(syntaxErrorPrefix, err.Error()) } var (