`GREATEST/LEAST` on BIGINT UNSIGNED columns returns wrong result
- 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
mysql> CREATE TABLE t_bigint (a BIGINT UNSIGNED, b BIGINT UNSIGNED);
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO t_bigint VALUES (9223372036854775807, 9223372036854775808);
Query OK, 1 row affected (0.00 sec)
mysql> SELECT GREATEST(a, b), LEAST(a, b) FROM t_bigint;
+---------------------+---------------------+
| GREATEST(a, b) | LEAST(a, b) |
+---------------------+---------------------+
| 9223372036854775807 | 9223372036854775808 |
+---------------------+---------------------+
1 row in set (0.00 sec)
```
### 2. What did you expect to see? (Required)
Since both columns are UNSIGNED, the comparison should be unsigned.
b (9223372036854775808) is greater than a (9223372036854775807).
```SQL
mysql> SELECT GREATEST(a, b), LEAST(a, b) FROM t_bigint;
+---------------------+---------------------+
| GREATEST(a, b) | LEAST(a, b) |
+---------------------+---------------------+
| 9223372036854775808 | 9223372036854775807 |
+---------------------+---------------------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.4.4 |
+-----------+
1 row in set (0.04 sec)
```
### 3. What did you see instead (Required)
```SQL
mysql> SELECT GREATEST(a, b), LEAST(a, b) FROM t_bigint;
+---------------------+---------------------+
| GREATEST(a, b) | LEAST(a, b) |
+---------------------+---------------------+
| 9223372036854775807 | 9223372036854775808 |
+---------------------+---------------------+
1 row in set (0.00 sec)
```
### 4. What is your TiDB version? (Required)
```SQL
mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-beta.2.pre-1236-gcbb1898ccf
Edition: Community
Git Commit Hash: cbb1898ccfebaac674438927157df8cc8e9247fa
Git Branch: master
UTC Build Time: 2026-02-13 02:04:43
GoVersion: go1.25.6
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Kernel Type: Classic |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.