pingcap/tidb

Arithmetic results are not consistent with MySQL when overflow occurs

Open

#4475 aperta il 8 set 2017

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Go (6186 fork)batch import
component/expressionhelp wantedpriority/P4type/compatibility

Metriche repository

Star
 (40.090 star)
Metriche merge PR
 (Merge medio 14g 4h) (346 PR mergiate in 30 g)

Descrizione

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a recipe for reproducing the error.
SET @a:=999999999999999;
select @a + @a;    -- 1999999999999998
SET @a:=9999999999999999;
select @a + @a;    -- 20000000000000000
SET @a:=99999999999999999;
select @a + @a;   -- 20000000000000000
select @a * @a; -- 1000000000000000000000000000000000000
SELECT -@a - @a;  -- -2000000000000000000
SELECT @a / 0.5; -- 2000000000000000000
select round(999999999999999999, -18);  -- tidb: 999999999999999872, mysql: 1000000000000000000
select round(9999999999999999999, -18);   -- tidb: 10446744073709552640, mysql: 100000000000000000000
  1. What did you expect to see?
@a + @a
1999999999999998
@a + @a
19999999999999998
@a + @a
199999999999999998
ERROR 1690 (22003) at line 7: BIGINT value is out of range in '((@`a`) * (@`a`))'
-@a - @a
-199999999999999998
@a / 0.5
199999999999999998.0000
round(999999999999999999, -18)
1000000000000000000
round(9999999999999999999, -18)
10000000000000000000
  1. What did you see instead?
@a + @a
1999999999999998
@a + @a
20000000000000000
@a + @a
200000000000000000
@a * @a
10000000000000000000000000000000000
-@a - @a
-200000000000000000
@a / 0.5
200000000000000000
round(999999999999999999, -18)
999999999999999872
round(9999999999999999999, -18)
10446744073709552640
  1. What version of TiDB are you using (tidb-server -V)?

Guida contributor