Behaviour of expression index is incompatible 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
CREATE TABLE t0 (c0 INT UNSIGNED);
CREATE INDEX i0 on t0 ((-c0));
INSERT INTO t0 (c0) VALUES (2147483649);
```
### 2. What did you expect to see? (Required)
```
ERROR 3752 (22003) at line 3: Value is out of range for functional index 'i0' at row 1
```
This is also the expected result in MySQL (8.0).
### 3. What did you see instead (Required)
no error.
#### Compatibility with MySQL
Based on trials, in MySQL the range of possible values for `c0` appears to be [0, 2147483648] while the range of possible values for `c0` in TiDB is [0, 4294967295]. This appears to be an incompatibility with MySQL's behaviour.
The snippet below demonstrates a series of insertions to guess the allowable values for `c0` in TiDB.
```
my:root@127.0.0.1:4000=> CREATE TABLE t0 (c0 INT UNSIGNED);
CREATE TABLE
my:root@127.0.0.1:4000=> CREATE INDEX i0 on t0 ((-c0));
CREATE INDEX
my:root@127.0.0.1:4000=> INSERT INTO t0 (c0) VALUES (2147483649);
INSERT 1
my:root@127.0.0.1:4000=> INSERT INTO t0 (c0) VALUES (2147483650);
INSERT 1
my:root@127.0.0.1:4000=> INSERT INTO t0 (c0) VALUES (4294967295);
INSERT 1
my:root@127.0.0.1:4000=> INSERT INTO t0 (c0) VALUES (4294967296);
error: mysql: 1264: Out of range value for column 'c0' at row 1
```
### 4. What is your TiDB version? (Required)
```
tidb_version()
-----------------------------------------------------------
Release Version: v8.5.1 +
Edition: Community +
Git Commit Hash: fea86c8e35ad4a86a5e1160701f99493c2ee547c+
Git Branch: HEAD +
UTC Build Time: 2025-01-16 07:40:33 +
GoVersion: go1.23.2 +
Race Enabled: false +
Check Table Before Drop: false +
Store: tikv
(1 row)
```
Contributor guide
Assessment
This issue has not been assessed yet.