pingcap/tidb

Arithmetic results are not consistent with MySQL when overflow occurs

Open

#4 475 ouverte le 8 sept. 2017

Voir sur GitHub
 (2 commentaires) (0 réactions) (0 assignés)Go (6 186 forks)batch import
component/expressionhelp wantedpriority/P4type/compatibility

Métriques du dépôt

Stars
 (40 090 stars)
Métriques de merge PR
 (Merge moyen 14j 4h) (346 PRs mergées en 30 j)

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

Guide contributeur