Strange transaction results caused by "Truncated incorrect INTEGER value"
- 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)
**Setup the environment:**
```
tiup playground &
mysql -h "127.0.0.1" -u root -P 4000
MySQL> create database testdb;
MySQL> \q
mysql -h "127.0.0.1" -u root -P 4000 -D testdb < mysql_bk.sql
```
mysql_bk.sql: [mysql_bk.txt](https://github.com/pingcap/tidb/files/9267035/mysql_bk.txt)
**Test case 1**
```
mysql -h "127.0.0.1" -u root -P 4000 -D testdb
mysql> delete from t_pjxdzd;
mysql> select * from t_kkdrvd
where LOG(t_kkdrvd.c_4wxknd) not in (
select 1 from t_pjxdzd as ref_0
where 10 between (null % CRC32('lcc8id' || 'n_5gbd'))
and case when ref_0.wkey is NULL then 49 else (49 / 45) end);
mysql> update t_kkdrvd set
wkey = 92
where LOG(t_kkdrvd.c_4wxknd) not in (
select 1 from t_pjxdzd as ref_0
where 10 between (null % CRC32('lcc8id' || 'n_5gbd'))
and case when ref_0.wkey is NULL then 49 else (49 / 45) end);
```
**Test case 2**
```
mysql -h "127.0.0.1" -u root -P 4000 -D testdb
mysql> BEGIN OPTIMISTIC;
mysql> delete from t_pjxdzd;
mysql> select * from t_kkdrvd
where LOG(t_kkdrvd.c_4wxknd) not in (
select 1 from t_pjxdzd as ref_0
where 10 between (null % CRC32('lcc8id' || 'n_5gbd'))
and case when ref_0.wkey is NULL then 49 else (49 / 45) end);
mysql> update t_kkdrvd set
wkey = 92
where LOG(t_kkdrvd.c_4wxknd) not in (
select 1 from t_pjxdzd as ref_0
where 10 between (null % CRC32('lcc8id' || 'n_5gbd'))
and case when ref_0.wkey is NULL then 49 else (49 / 45) end);
mysql> COMMIT;
```
### 2. What did you expect to see? (Required)
1) The behaviors of Test case 1 and Test case 2 should be same.
2) In Test case 2, UPDATE should exactly change the rows outputted by the earlier SELECT, because the UPDATE and SELECT have the same WHERE clause
### 3. What did you see instead (Required)
1) The UPDATE in Test case 1 changes 9 rows, while the UPDATE in Test case 2 outputs an error "Truncated incorrect INTEGER value: 'lcc8id'"
2) The SELECT in Test case 2 output 9 rows, while the UPDATE in Test case 2 fails to update these rows.
### 4. What is your TiDB version? (Required)
```
Release Version: v6.1.0
Edition: Community
Git Commit Hash: 1a89decdb192cbdce6a7b0020d71128bc964d30f
Git Branch: HEAD
UTC Build Time: 2022-08-01 09:18:07
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.