pingcap / pingcap/tidb

Data truncation error occurs in update statement.

Open
#57,650 4 comments 0 reactions 0 assignees View on GitHub
affects-8.1 affects-8.4 severity/moderate sig/execution type/bug
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. schema.

```sql
create table t1(c1 CHAR(16));
insert into t1 values('G');
```

2. sql statement.

```sql
UPDATE t1 SET c1="b+F6rUuv?" WHERE (("-1433326829") LIKE (1909913287)) IN ((0), ((1.790079046E9)IS FALSE), (c1), (-1512320610));
```

### 2. What did you expect to see? (Required)

MySQL and TIDB have different execution results in the above case.

The normal result in MySQL 8:

```SQL
mysql> UPDATE t1 SET c1="b+F6rUuv?" WHERE (("-1433326829") LIKE (1909913287)) IN ((0), ((1.790079046E9)IS FALSE), (c1), (-1512320610));
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from t1;
+-----------+
| c1 |
+-----------+
| b+F6rUuv? |
+-----------+
1 row in set (0.00 sec)
```

TiDB should also return the same result, but failed.

### 3. What did you see instead (Required)

In TiDB v8.1.1:

```sql
MySQL [test]> UPDATE t1 SET c1="b+F6rUuv?" WHERE (("-1433326829") LIKE (1909913287)) IN ((0), ((1.790079046E9)IS FALSE), (c1), (-1512320610));
ERROR 1292 (22007): Truncated incorrect INTEGER value: 'G'
```

Afterwards, I wondered if the error was caused by predicate, so I constructed the same predicate using a select statement.

The following result is correct:

```SQL
MySQL [test]> select * from t1 WHERE (("-1433326829") LIKE (1909913287)) IN ((0), ((1.790079046E9)IS FALSE), (c1), (-1512320610));
+------+
| c1 |
+------+
| G |
+------+
1 row in set, 1 warning (0.02 sec)
```

The predicate is the same, but the results of the select and update statements are different in TiDB.

### 4. What is your TiDB version? (Required)

Tidb v8.1.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.