`UPDATE IGNORE` incorrectly bypasses foreign key constraint and modifies parent row
- 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
mysql> create table parent (id int primary key, ref int, key(ref));
Query OK, 0 rows affected (0.02 sec)
mysql> create table child (id int primary key, ref int, foreign key (ref) references parent(ref));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into parent values (1, 1), (2, 2);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into child values (1, 2);
Query OK, 1 row affected (0.00 sec)
mysql> update parent set ref = 3 where id = 2;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `fk_1` FOREIGN KEY (`ref`) REFERENCES `parent` (`ref`))
mysql> select * from parent;
+----+------+
| id | ref |
+----+------+
| 1 | 1 |
| 2 | 2 |
+----+------+
2 rows in set (0.00 sec)
mysql> update ignore parent set ref = 3 where id = 2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> show warnings;
Empty set (0.00 sec)
mysql> select * from parent;
+----+------+
| id | ref |
+----+------+
| 1 | 1 |
| 2 | 3 |
+----+------+
2 rows in set (0.00 sec)
```
### 2. What did you expect to see? (Required)
The statement with IGNORE should downgrade the error to a warning and skip the update for the conflicting row. The data in the parent table should remain unchanged to preserve the foreign key constraint.
```SQL
mysql> update ignore parent set ref = 3 where id = 2;
Query OK, 0 rows affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1451 | Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`ref`) REFERENCES `parent` (`ref`)) |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> select * from parent;
+----+------+
| id | ref |
+----+------+
| 1 | 1 |
| 2 | 2 |
+----+------+
2 rows in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.45 |
+-----------+
1 row in set (0.03 sec)
```
### 3. What did you see instead (Required)
```SQL
mysql> update ignore parent set ref = 3 where id = 2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> show warnings;
Empty set (0.00 sec)
mysql> select * from parent;
+----+------+
| id | ref |
+----+------+
| 1 | 1 |
| 2 | 3 |
+----+------+
2 rows in set (0.00 sec)
```
### 4. What is your TiDB version? (Required)
```SQL
mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-beta.2.pre-1329-geb6a9c9fae
Edition: Community
Git Commit Hash: eb6a9c9fae60fed8b062ffc5a27f7c69cc42c9d8
Git Branch: master
UTC Build Time: 2026-03-10 03:06:59
GoVersion: go1.25.6
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Kernel Type: Classic |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.