pingcap / pingcap/tidb

DELETE statement has inconsistent behavior within and outside a transaction

Open
#64,412 1 comment 0 reactions 0 assignees View on GitHub
contribution 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)

```sql
/* init */ DROP TABLE IF EXISTS t;
/* init */ CREATE TABLE t (c1 INT, UNIQUE (c1));

-- not in transaction
/* s */ INSERT INTO t(c1) VALUES (-4);
/* s */ DELETE FROM t WHERE NOT (('23' + INTERVAL '52' HOUR_MICROSECOND) IS NOT NULL); -- [1]
/* s */ SELECT * FROM t; -- [2]

-- in transaction
/* t1 */ BEGIN;
/* t1 */ INSERT INTO t(c1) VALUES (-4);
/* t1 */ DELETE FROM t WHERE NOT (('23' + INTERVAL '52' HOUR_MICROSECOND) IS NOT NULL); -- [3]
/* t1 */ COMMIT;
/* t1 */ SELECT * FROM t; -- [4]
```

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

The error messages reported by the DELETE statements [1] and [3] are the same. The final SELECT statements [2] and [4] return the same results.

### 3. What did you see instead (Required)
The DELETE statement [1] does not report an error, while the DELETE statement [3] reports an error.
The final SELECT statement [2] returns an empty set, while the final SELECT statement [4] returns [(-4)].

DELETE not in a transaction:
```sql
mysql> INSERT INTO t(c1) VALUES (-4);
Query OK, 1 row affected (0.02 sec)

mysql> DELETE FROM t WHERE NOT (('23' + INTERVAL '52' HOUR_MICROSECOND) IS NOT NULL);
Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> SELECT * FROM t;
Empty set (0.01 sec)
```

DELETE in a transaction:
```sql
mysql> BEGIN;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t(c1) VALUES (-4);
Query OK, 1 row affected (0.02 sec)

mysql> DELETE FROM t WHERE NOT (('23' + INTERVAL '52' HOUR_MICROSECOND) IS NOT NULL);
ERROR 1292 (22007): Incorrect time value: '23'

mysql> COMMIT;
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT * FROM t;
+------+
| c1 |
+------+
| -4 |
+------+
1 row in set (0.00 sec)
```

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

```sql
Release Version: v8.5.3
Edition: Community
Git Commit Hash: dc2548aac79a712265e831cff2a3a896bc0a5a38
Git Branch: HEAD
UTC Build Time: 2025-07-31 13:54:43
GoVersion: go1.23.8
Race Enabled: false
Check Table Before Drop: false
Store: tikv
```

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.