@@ -18,6 +18,7 @@ import (
1818 "fmt"
1919 "math"
2020
21+ "github.com/pingcap/errors"
2122 "github.com/pingcap/tidb/pkg/parser/mysql"
2223 "github.com/pingcap/tidb/pkg/parser/terror"
2324 "github.com/pingcap/tidb/pkg/types"
@@ -225,25 +226,25 @@ func (s *builtinArithmeticPlusIntSig) evalInt(ctx EvalContext, row chunk.Row) (v
225226 switch {
226227 case isLHSUnsigned && isRHSUnsigned :
227228 if uint64 (a ) > math .MaxUint64 - uint64 (b ) {
228- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
229+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
229230 }
230231 case isLHSUnsigned && ! isRHSUnsigned :
231232 if b < 0 && uint64 (- b ) > uint64 (a ) {
232- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
233+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
233234 }
234235 if b > 0 && uint64 (a ) > math .MaxUint64 - uint64 (b ) {
235- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
236+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
236237 }
237238 case ! isLHSUnsigned && isRHSUnsigned :
238239 if a < 0 && uint64 (- a ) > uint64 (b ) {
239- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
240+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
240241 }
241242 if a > 0 && uint64 (b ) > math .MaxUint64 - uint64 (a ) {
242- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
243+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
243244 }
244245 case ! isLHSUnsigned && ! isRHSUnsigned :
245246 if (a > 0 && b > math .MaxInt64 - a ) || (a < 0 && b < math .MinInt64 - a ) {
246- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
247+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
247248 }
248249 }
249250
@@ -273,7 +274,7 @@ func (s *builtinArithmeticPlusDecimalSig) evalDecimal(ctx EvalContext, row chunk
273274 err = types .DecimalAdd (a , b , c )
274275 if err != nil {
275276 if err == types .ErrOverflow {
276- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
277+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
277278 }
278279 return nil , true , err
279280 }
@@ -303,7 +304,7 @@ func (s *builtinArithmeticPlusRealSig) evalReal(ctx EvalContext, row chunk.Row)
303304 return 0 , true , nil
304305 }
305306 if ! mathutil .IsFinite (a + b ) {
306- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
307+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
307308 }
308309 return a + b , false , nil
309310}
@@ -368,7 +369,7 @@ func (s *builtinArithmeticMinusRealSig) evalReal(ctx EvalContext, row chunk.Row)
368369 return 0 , isNull , err
369370 }
370371 if ! mathutil .IsFinite (a - b ) {
371- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
372+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
372373 }
373374 return a - b , false , nil
374375}
@@ -396,7 +397,7 @@ func (s *builtinArithmeticMinusDecimalSig) evalDecimal(ctx EvalContext, row chun
396397 err = types .DecimalSub (a , b , c )
397398 if err != nil {
398399 if err == types .ErrOverflow {
399- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
400+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
400401 }
401402 return nil , true , err
402403 }
@@ -434,7 +435,7 @@ func (s *builtinArithmeticMinusIntSig) evalInt(ctx EvalContext, row chunk.Row) (
434435 }
435436 overflow := s .overflowCheck (isLHSUnsigned , isRHSUnsigned , signed , a , b )
436437 if overflow {
437- return 0 , true , types .ErrOverflow .GenWithStackByArgs (errType , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
438+ return 0 , true , types .ErrOverflow .GenWithStackByArgs (errType , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
438439 }
439440
440441 return a - b , false , nil
@@ -578,7 +579,7 @@ func (s *builtinArithmeticMultiplyRealSig) evalReal(ctx EvalContext, row chunk.R
578579 }
579580 result := a * b
580581 if math .IsInf (result , 0 ) {
581- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
582+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
582583 }
583584 return result , false , nil
584585}
@@ -596,7 +597,7 @@ func (s *builtinArithmeticMultiplyDecimalSig) evalDecimal(ctx EvalContext, row c
596597 err = types .DecimalMul (a , b , c )
597598 if err != nil && ! terror .ErrorEqual (err , types .ErrTruncated ) {
598599 if err == types .ErrOverflow {
599- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
600+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
600601 }
601602 return nil , true , err
602603 }
@@ -616,7 +617,7 @@ func (s *builtinArithmeticMultiplyIntUnsignedSig) evalInt(ctx EvalContext, row c
616617 unsignedB := uint64 (b )
617618 result := unsignedA * unsignedB
618619 if unsignedA != 0 && result / unsignedA != unsignedB {
619- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
620+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
620621 }
621622 return int64 (result ), false , nil
622623}
@@ -632,7 +633,7 @@ func (s *builtinArithmeticMultiplyIntSig) evalInt(ctx EvalContext, row chunk.Row
632633 }
633634 result := a * b
634635 if (a != 0 && result / a != b ) || (result == math .MinInt64 && a == - 1 ) {
635- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
636+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
636637 }
637638 return result , false , nil
638639}
@@ -697,7 +698,7 @@ func (s *builtinArithmeticDivideRealSig) evalReal(ctx EvalContext, row chunk.Row
697698 }
698699 result := a / b
699700 if math .IsInf (result , 0 ) {
700- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
701+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
701702 }
702703 return result , false , nil
703704}
@@ -726,7 +727,7 @@ func (s *builtinArithmeticDivideDecimalSig) evalDecimal(ctx EvalContext, row chu
726727 err = c .Round (c , s .baseBuiltinFunc .tp .GetDecimal (), types .ModeHalfUp )
727728 }
728729 } else if err == types .ErrOverflow {
729- err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
730+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
730731 }
731732 return c , false , err
732733}
@@ -857,14 +858,14 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(ctx EvalContext, row chun
857858 ret = int64 (0 )
858859 return ret , false , nil
859860 }
860- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
861+ 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 )))
861862 }
862863 ret = int64 (val )
863864 } else {
864865 ret , err = c .ToInt ()
865866 // err returned by ToInt may be ErrTruncated or ErrOverflow, only handle ErrOverflow, ignore ErrTruncated.
866867 if err == types .ErrOverflow {
867- return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].String ( ), s .args [1 ].String ( )))
868+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].StringWithCtx ( errors . RedactLogDisable ), s .args [1 ].StringWithCtx ( errors . RedactLogDisable )))
868869 }
869870 }
870871
0 commit comments