@@ -18,6 +18,7 @@ import (
18
18
"fmt"
19
19
"math"
20
20
21
+ "github.com/pingcap/errors"
21
22
"github.com/pingcap/tidb/pkg/parser/mysql"
22
23
"github.com/pingcap/tidb/pkg/parser/terror"
23
24
"github.com/pingcap/tidb/pkg/sessionctx"
@@ -231,25 +232,25 @@ func (s *builtinArithmeticPlusIntSig) evalInt(row chunk.Row) (val int64, isNull
231
232
switch {
232
233
case isLHSUnsigned && isRHSUnsigned :
233
234
if uint64 (a ) > math .MaxUint64 - uint64 (b ) {
234
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
235
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
235
236
}
236
237
case isLHSUnsigned && ! isRHSUnsigned :
237
238
if b < 0 && uint64 (- b ) > uint64 (a ) {
238
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
239
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
239
240
}
240
241
if b > 0 && uint64 (a ) > math .MaxUint64 - uint64 (b ) {
241
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
242
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
242
243
}
243
244
case ! isLHSUnsigned && isRHSUnsigned :
244
245
if a < 0 && uint64 (- a ) > uint64 (b ) {
245
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
246
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
246
247
}
247
248
if a > 0 && uint64 (b ) > math .MaxUint64 - uint64 (a ) {
248
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
249
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
249
250
}
250
251
case ! isLHSUnsigned && ! isRHSUnsigned :
251
252
if (a > 0 && b > math .MaxInt64 - a ) || (a < 0 && b < math .MinInt64 - a ) {
252
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
253
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
253
254
}
254
255
}
255
256
@@ -279,7 +280,7 @@ func (s *builtinArithmeticPlusDecimalSig) evalDecimal(row chunk.Row) (*types.MyD
279
280
err = types .DecimalAdd (a , b , c )
280
281
if err != nil {
281
282
if err == types .ErrOverflow {
282
- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
283
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
283
284
}
284
285
return nil , true , err
285
286
}
@@ -309,7 +310,7 @@ func (s *builtinArithmeticPlusRealSig) evalReal(row chunk.Row) (float64, bool, e
309
310
return 0 , true , nil
310
311
}
311
312
if ! mathutil .IsFinite (a + b ) {
312
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
313
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
313
314
}
314
315
return a + b , false , nil
315
316
}
@@ -375,7 +376,7 @@ func (s *builtinArithmeticMinusRealSig) evalReal(row chunk.Row) (float64, bool,
375
376
return 0 , isNull , err
376
377
}
377
378
if ! mathutil .IsFinite (a - b ) {
378
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
379
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
379
380
}
380
381
return a - b , false , nil
381
382
}
@@ -403,7 +404,7 @@ func (s *builtinArithmeticMinusDecimalSig) evalDecimal(row chunk.Row) (*types.My
403
404
err = types .DecimalSub (a , b , c )
404
405
if err != nil {
405
406
if err == types .ErrOverflow {
406
- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
407
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
407
408
}
408
409
return nil , true , err
409
410
}
@@ -441,7 +442,7 @@ func (s *builtinArithmeticMinusIntSig) evalInt(row chunk.Row) (val int64, isNull
441
442
}
442
443
overflow := s .overflowCheck (isLHSUnsigned , isRHSUnsigned , signed , a , b )
443
444
if overflow {
444
- return 0 , true , types .ErrOverflow .GenWithStackByArgs (errType , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
445
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs (errType , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
445
446
}
446
447
447
448
return a - b , false , nil
@@ -586,7 +587,7 @@ func (s *builtinArithmeticMultiplyRealSig) evalReal(row chunk.Row) (float64, boo
586
587
}
587
588
result := a * b
588
589
if math .IsInf (result , 0 ) {
589
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
590
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
590
591
}
591
592
return result , false , nil
592
593
}
@@ -604,7 +605,7 @@ func (s *builtinArithmeticMultiplyDecimalSig) evalDecimal(row chunk.Row) (*types
604
605
err = types .DecimalMul (a , b , c )
605
606
if err != nil && ! terror .ErrorEqual (err , types .ErrTruncated ) {
606
607
if err == types .ErrOverflow {
607
- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
608
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
608
609
}
609
610
return nil , true , err
610
611
}
@@ -624,7 +625,7 @@ func (s *builtinArithmeticMultiplyIntUnsignedSig) evalInt(row chunk.Row) (val in
624
625
unsignedB := uint64 (b )
625
626
result := unsignedA * unsignedB
626
627
if unsignedA != 0 && result / unsignedA != unsignedB {
627
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
628
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
628
629
}
629
630
return int64 (result ), false , nil
630
631
}
@@ -640,7 +641,7 @@ func (s *builtinArithmeticMultiplyIntSig) evalInt(row chunk.Row) (val int64, isN
640
641
}
641
642
result := a * b
642
643
if (a != 0 && result / a != b ) || (result == math .MinInt64 && a == - 1 ) {
643
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
644
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
644
645
}
645
646
return result , false , nil
646
647
}
@@ -705,7 +706,7 @@ func (s *builtinArithmeticDivideRealSig) evalReal(row chunk.Row) (float64, bool,
705
706
}
706
707
result := a / b
707
708
if math .IsInf (result , 0 ) {
708
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
709
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
709
710
}
710
711
return result , false , nil
711
712
}
@@ -734,7 +735,7 @@ func (s *builtinArithmeticDivideDecimalSig) evalDecimal(row chunk.Row) (*types.M
734
735
err = c .Round (c , s .baseBuiltinFunc .tp .GetDecimal (), types .ModeHalfUp )
735
736
}
736
737
} else if err == types .ErrOverflow {
737
- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
738
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
738
739
}
739
740
return c , false , err
740
741
}
@@ -869,14 +870,14 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row chunk.Row) (ret int64
869
870
ret = int64 (0 )
870
871
return ret , false , nil
871
872
}
872
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
873
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
873
874
}
874
875
ret = int64 (val )
875
876
} else {
876
877
ret , err = c .ToInt ()
877
878
// err returned by ToInt may be ErrTruncated or ErrOverflow, only handle ErrOverflow, ignore ErrTruncated.
878
879
if err == types .ErrOverflow {
879
- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
880
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
880
881
}
881
882
}
882
883
0 commit comments