pingcap/tidb

Arithmetic results are not consistent with MySQL when overflow occurs

Open

#4,475 opened on Sep 8, 2017

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Go (6,186 forks)batch import
component/expressionhelp wantedpriority/P4type/compatibility

Repository metrics

Stars
 (40,090 stars)
PR merge metrics
 (Avg merge 14d 4h) (346 merged PRs in 30d)

Description

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)?

Contributor guide