Constant overflow when querying a negative number on unsigned column
- 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)
1. prepare data
```sql
CREATE TABLE `tbl_1` (
`col_1` mediumint(9) NOT NULL,
`col_4` year(4) DEFAULT '2010'
) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_chinese_ci;
CREATE TABLE `tbl_2` (
`col_11` year(4) NOT NULL,
`col_15` mediumint(8) unsigned NOT NULL,
PRIMARY KEY (`col_15`,`col_11`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT INTO `tbl_1` VALUES (7115365,'2010');
INSERT INTO `tbl_2` VALUES ('2013',15963235);
```
2. reproduce
```sql
update tbl_1 set tbl_1.col_4 = '2024' where tbl_1.col_1 in ( select col_15 from tbl_2 where tbl_1.col_1 in (-3227144 ,3061647 ) );
```
### 2. What did you expect to see? (Required)
Execute success, since mysql will execute success.
### 3. What did you see instead (Required)
```sql
> update tbl_1 set tbl_1.col_4 = '2024' where tbl_1.col_1 in ( select col_15 from tbl_2 where tbl_1.col_1 in (-3227144 ,3061647 ) );
(1690, 'constant -3227144 overflows bigint')
```
### 4. What is your TiDB version? (Required)
```sql
***************************[ 1. row ]***************************
tidb_version() | Release Version: v6.1.0-alpha-432-gd75b06ec97
Edition: Community
Git Commit Hash: d75b06ec97e54ef9f5a15630e7dfee30d22f047e
Git Branch: master
UTC Build Time: 2022-05-17 07:29:42
GoVersion: go1.18
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
```
Contributor guide
Assessment
This issue has not been assessed yet.