@@ -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,6 +232,7 @@ 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 ) {
235
+ << << << < HEAD
234
236
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String (), s .args [1 ].String ()))
235
237
}
236
238
case isLHSUnsigned && ! isRHSUnsigned :
@@ -250,6 +252,27 @@ func (s *builtinArithmeticPlusIntSig) evalInt(row chunk.Row) (val int64, isNull
250
252
case ! isLHSUnsigned && ! isRHSUnsigned :
251
253
if (a > 0 && b > math .MaxInt64 - a ) || (a < 0 && b < math .MinInt64 - a ) {
252
254
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String (), s .args [1 ].String ()))
255
+ == == == =
256
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
257
+ }
258
+ case isLHSUnsigned && ! isRHSUnsigned :
259
+ if b < 0 && uint64 (- b ) > uint64 (a ) {
260
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
261
+ }
262
+ if b > 0 && uint64 (a ) > math .MaxUint64 - uint64 (b ) {
263
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
264
+ }
265
+ case ! isLHSUnsigned && isRHSUnsigned :
266
+ if a < 0 && uint64 (- a ) > uint64 (b ) {
267
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
268
+ }
269
+ if a > 0 && uint64 (b ) > math .MaxUint64 - uint64 (a ) {
270
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
271
+ }
272
+ case ! isLHSUnsigned && ! isRHSUnsigned :
273
+ if (a > 0 && b > math .MaxInt64 - a ) || (a < 0 && b < math .MinInt64 - a ) {
274
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
275
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
253
276
}
254
277
}
255
278
@@ -279,7 +302,11 @@ func (s *builtinArithmeticPlusDecimalSig) evalDecimal(row chunk.Row) (*types.MyD
279
302
err = types .DecimalAdd (a , b , c )
280
303
if err != nil {
281
304
if err == types.ErrOverflow {
305
+ << << << < HEAD
282
306
err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String (), s .args [1 ].String ()))
307
+ == == == =
308
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
309
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
283
310
}
284
311
return nil , true , err
285
312
}
@@ -309,7 +336,11 @@ func (s *builtinArithmeticPlusRealSig) evalReal(row chunk.Row) (float64, bool, e
309
336
return 0 , true , nil
310
337
}
311
338
if ! mathutil .IsFinite (a + b ) {
339
+ << << << < HEAD
312
340
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].String (), s .args [1 ].String ()))
341
+ == == == =
342
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s + %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
343
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
313
344
}
314
345
return a + b , false , nil
315
346
}
@@ -375,7 +406,11 @@ func (s *builtinArithmeticMinusRealSig) evalReal(row chunk.Row) (float64, bool,
375
406
return 0 , isNull , err
376
407
}
377
408
if ! mathutil .IsFinite (a - b ) {
409
+ << << << < HEAD
378
410
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String (), s .args [1 ].String ()))
411
+ == == == =
412
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
413
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
379
414
}
380
415
return a - b , false , nil
381
416
}
@@ -403,7 +438,11 @@ func (s *builtinArithmeticMinusDecimalSig) evalDecimal(row chunk.Row) (*types.My
403
438
err = types .DecimalSub (a , b , c )
404
439
if err != nil {
405
440
if err == types.ErrOverflow {
441
+ << << << < HEAD
406
442
err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String (), s .args [1 ].String ()))
443
+ == == == =
444
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
445
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
407
446
}
408
447
return nil , true , err
409
448
}
@@ -441,7 +480,11 @@ func (s *builtinArithmeticMinusIntSig) evalInt(row chunk.Row) (val int64, isNull
441
480
}
442
481
overflow := s .overflowCheck (isLHSUnsigned , isRHSUnsigned , signed , a , b )
443
482
if overflow {
483
+ << << << < HEAD
444
484
return 0 , true , types .ErrOverflow .GenWithStackByArgs (errType , fmt .Sprintf ("(%s - %s)" , s .args [0 ].String (), s .args [1 ].String ()))
485
+ == == == =
486
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs (errType , fmt .Sprintf ("(%s - %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
487
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
445
488
}
446
489
447
490
return a - b , false , nil
@@ -586,7 +629,11 @@ func (s *builtinArithmeticMultiplyRealSig) evalReal(row chunk.Row) (float64, boo
586
629
}
587
630
result := a * b
588
631
if math .IsInf (result , 0 ) {
632
+ << << << < HEAD
589
633
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String (), s .args [1 ].String ()))
634
+ == == == =
635
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
636
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
590
637
}
591
638
return result , false , nil
592
639
}
@@ -604,7 +651,11 @@ func (s *builtinArithmeticMultiplyDecimalSig) evalDecimal(row chunk.Row) (*types
604
651
err = types .DecimalMul (a , b , c )
605
652
if err != nil && ! terror .ErrorEqual (err , types .ErrTruncated ) {
606
653
if err == types.ErrOverflow {
654
+ << << << < HEAD
607
655
err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String (), s .args [1 ].String ()))
656
+ == == == =
657
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
658
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
608
659
}
609
660
return nil , true , err
610
661
}
@@ -624,7 +675,11 @@ func (s *builtinArithmeticMultiplyIntUnsignedSig) evalInt(row chunk.Row) (val in
624
675
unsignedB := uint64 (b )
625
676
result := unsignedA * unsignedB
626
677
if unsignedA != 0 && result / unsignedA != unsignedB {
678
+ << << << < HEAD
627
679
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String (), s .args [1 ].String ()))
680
+ == == == =
681
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
682
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
628
683
}
629
684
return int64 (result ), false , nil
630
685
}
@@ -640,7 +695,11 @@ func (s *builtinArithmeticMultiplyIntSig) evalInt(row chunk.Row) (val int64, isN
640
695
}
641
696
result := a * b
642
697
if (a != 0 && result / a != b ) || (result == math .MinInt64 && a == - 1 ) {
698
+ << << << < HEAD
643
699
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].String (), s .args [1 ].String ()))
700
+ == == == =
701
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s * %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
702
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
644
703
}
645
704
return result , false , nil
646
705
}
@@ -705,7 +764,11 @@ func (s *builtinArithmeticDivideRealSig) evalReal(row chunk.Row) (float64, bool,
705
764
}
706
765
result := a / b
707
766
if math .IsInf (result , 0 ) {
767
+ << << << < HEAD
708
768
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].String (), s .args [1 ].String ()))
769
+ == == == =
770
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("DOUBLE" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
771
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
709
772
}
710
773
return result , false , nil
711
774
}
@@ -734,7 +797,11 @@ func (s *builtinArithmeticDivideDecimalSig) evalDecimal(row chunk.Row) (*types.M
734
797
err = c .Round (c , s .baseBuiltinFunc .tp .GetDecimal (), types .ModeHalfUp )
735
798
}
736
799
} else if err == types.ErrOverflow {
800
+ << << << < HEAD
737
801
err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].String (), s .args [1 ].String ()))
802
+ == == == =
803
+ err = types .ErrOverflow .GenWithStackByArgs ("DECIMAL" , fmt .Sprintf ("(%s / %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
804
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
738
805
}
739
806
return c , false , err
740
807
}
@@ -869,14 +936,22 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row chunk.Row) (ret int64
869
936
ret = int64 (0 )
870
937
return ret , false , nil
871
938
}
939
+ << << << < HEAD
872
940
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].String (), s .args [1 ].String ()))
941
+ == == == =
942
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT UNSIGNED" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
943
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
873
944
}
874
945
ret = int64 (val )
875
946
} else {
876
947
ret , err = c .ToInt ()
877
948
// err returned by ToInt may be ErrTruncated or ErrOverflow, only handle ErrOverflow, ignore ErrTruncated.
878
949
if err == types.ErrOverflow {
950
+ << << << < HEAD
879
951
return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].String (), s .args [1 ].String ()))
952
+ == == == =
953
+ return 0 , true , types .ErrOverflow .GenWithStackByArgs ("BIGINT" , fmt .Sprintf ("(%s DIV %s)" , s .args [0 ].StringWithCtx (ctx , errors .RedactLogDisable ), s .args [1 ].StringWithCtx (ctx , errors .RedactLogDisable )))
954
+ >> >> >> > f5ac1c4a453 (* : support tidb_redact_log for explain (#54553 ))
880
955
}
881
956
}
882
957
0 commit comments