Skip to content

Commit

Permalink
remove unnecessary expensive trace call and log from hot path (pingca…
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaut authored Apr 3, 2019
1 parent eedbc8d commit 76a01da
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
6 changes: 2 additions & 4 deletions executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package executor

import (
"context"
"fmt"

"github.com/pingcap/errors"
"github.com/pingcap/parser/ast"
Expand Down Expand Up @@ -386,7 +385,7 @@ func (e *InsertValues) filterErr(err error) error {
return err
}
// TODO: should not filter all types of errors here.
e.handleWarning(err, fmt.Sprintf("ignore err:%v", errors.ErrorStack(err)))
e.handleWarning(err)
return nil
}

Expand Down Expand Up @@ -522,10 +521,9 @@ func (e *InsertValues) adjustAutoIncrementDatum(d types.Datum, hasValue bool, c
return casted, nil
}

func (e *InsertValues) handleWarning(err error, logInfo string) {
func (e *InsertValues) handleWarning(err error) {
sc := e.ctx.GetSessionVars().StmtCtx
sc.AppendWarning(err)
logutil.Logger(context.Background()).Warn(logInfo)
}

// batchCheckAndInsert checks rows with duplicate errors.
Expand Down
6 changes: 2 additions & 4 deletions executor/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ func (e *LoadDataInfo) colsToRow(cols []field) []types.Datum {
}
row, err := e.getRow(e.row)
if err != nil {
e.handleWarning(err,
fmt.Sprintf("Load Data: insert data:%v failed:%v", e.row, errors.ErrorStack(err)))
e.handleWarning(err)
return nil
}
return row
Expand All @@ -302,8 +301,7 @@ func (e *LoadDataInfo) addRecordLD(row []types.Datum) (int64, error) {
}
h, err := e.addRecord(row)
if err != nil {
e.handleWarning(err,
fmt.Sprintf("Load Data: insert data:%v failed:%v", e.row, errors.ErrorStack(err)))
e.handleWarning(err)
}
return h, nil
}
Expand Down
2 changes: 1 addition & 1 deletion table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo) (
// TODO: make sure all truncate errors are handled by ConvertTo.
err = sc.HandleTruncate(err)
if err != nil {
return casted, errors.Trace(err)
return casted, err
}

if col.Tp == mysql.TypeString && !types.IsBinaryStr(&col.FieldType) {
Expand Down
6 changes: 3 additions & 3 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ func (d *Datum) convertToMysqlDecimal(sc *stmtctx.StatementContext, target *Fiel
}
}
ret.SetValue(dec)
return ret, errors.Trace(err)
return ret, err
}

// ProduceDecWithSpecifiedTp produces a new decimal according to `flen` and `decimal`.
Expand All @@ -1150,7 +1150,7 @@ func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.Statem
old := *dec
err = dec.Round(dec, decimal, ModeHalfEven)
if err != nil {
return nil, errors.Trace(err)
return nil, err
}
if !dec.IsZero() && frac > decimal && dec.Compare(&old) != 0 {
if sc.InInsertStmt || sc.InUpdateStmt || sc.InDeleteStmt {
Expand All @@ -1173,7 +1173,7 @@ func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.Statem
if unsigned && dec.IsNegative() {
dec = dec.FromUint(0)
}
return dec, errors.Trace(err)
return dec, err
}

func (d *Datum) convertToMysqlYear(sc *stmtctx.StatementContext, target *FieldType) (Datum, error) {
Expand Down

0 comments on commit 76a01da

Please sign in to comment.