pingcap / pingcap/tidb

TiDB and TiKV's cast float as data/datetime are inconsistent with MySQL

Open
#52,934 5 comments 0 reactions 0 assignees View on GitHub
affects-8.1 affects-8.5 impact/wrong-result may-affects-5.4 may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```SQL
CREATE TABLE t0 (
c0 decimal(10, 0) NOT NULL,
c1 float unsigned zerofill NOT NULL,
PRIMARY KEY (c0, c1)
);

INSERT INTO t0 VALUES (-2068985011, 0.75245386), (-668435082, 0.19411194), (-500731198, 0.39079505), (0, 0), (0, 0.9938275), (12196703, 970789000), (919009011, 0.28699672), (1069380201, 0.2576304);

SELECT t0.c0 FROM t0 GROUP BY t0.c0, CAST(t0.c1 AS DATE), t0.c0 OR '' HAVING NOT (t0.c0);
```

### 2. What did you expect to see? (Required)

```SQL
+----+
| c0 |
+----+
| 0 |
+----+
```

### 3. What did you see instead (Required)
The query results provided by TiDB are unstable, and there is a small probability of different results(Result 1 and Result 2) occurring when the same query is executed multiple times.
```SQL
Result 1:
MySQL> SELECT t0.c0 FROM t0 GROUP BY t0.c0, CAST(t0.c1 AS DATE), t0.c0 OR '' HAVING NOT (t0.c0);
+----+
| c0 |
+----+
| 0 |
+----+
1 row in set (0.002 sec)

Result 2:
MySQL> SELECT t0.c0 FROM t0 GROUP BY t0.c0, CAST(t0.c1 AS DATE), t0.c0 OR '' HAVING NOT (t0.c0);
+----+
| c0 |
+----+
| 0 |
| 0 |
+----+
2 rows in set, 1 warning (0.005 sec)
```

### 4. What is your TiDB version? (Required)

```SQL
MySQL> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.0.0
Edition: Community
Git Commit Hash: 8ba1fa452b1ccdbfb85879ea94b9254aabba2916
Git Branch: HEAD
UTC Build Time: 2024-03-28 14:22:04
GoVersion: go1.21.6
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.002 sec)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.