Wrong result of LEAST function in TiDB with MySQL
- 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
DROP TABLE IF EXISTS t0;
CREATE TABLE IF NOT EXISTS t0(c0 TINYINT(200) ZEROFILL PRIMARY KEY UNIQUE) ;
INSERT IGNORE INTO t0(c0) VALUES(-149547112);
SELECT SUM(t0.c0) FROM t0 WHERE LEAST(t0.c0, "0.95");
```
### 2. What did you expect to see? (Required)
see the following case:
The MySQL manual clarifies that If the arguments comprise a mix of numbers and strings, they are compared as strings.
https://dev.mysql.com/doc/refman/9.1/en/comparison-operators.html#function_least
### 3. What did you see instead (Required)
```sql
// MySQL 8.4.1
MySQL [test]> select LEAST(t0.c0, "0.95") from t0;
+----------------------+
| LEAST(t0.c0, "0.95") |
+----------------------+
| 0.95 |
+----------------------+
1 row in set (0.00 sec)
MySQL [test]> SELECT SUM(t0.c0) FROM t0 WHERE LEAST(t0.c0, "0.95");
+------------+
| SUM(t0.c0) |
+------------+
| 0 |
+------------+
1 row in set (0.00 sec)
// TiDB
mysql> select LEAST(t0.c0, "0.95") from t0;
+----------------------+
| LEAST(t0.c0, "0.95") |
+----------------------+
| 0 |
+----------------------+
1 row in set (0.04 sec)
mysql> SELECT SUM(t0.c0) FROM t0 WHERE LEAST(t0.c0, "0.95");
+------------+
| SUM(t0.c0) |
+------------+
| NULL |
+------------+
1 row in set (0.04 sec)
```
### 4. What is your TiDB version? (Required)
TiDB v8.5.0
Contributor guide
Assessment
This issue has not been assessed yet.