oceanbase / oceanbase/oceanbase
[Bug]: Foreign key cascade update issue
@yfzcsc is already working on this.
Since May 22, 2024.
- Dominant language
- C++
- Stars
- 10.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
During foreign key cascade updates, it is possible for a single table to be updated simultaneously. In such cases, mysql reports an error, while oceanbase fails if a row is updated using two different versions. There are 2 scenarios:
(1) The update statement only updates one table. An error occurs if there is a cycle reference in tables. For example, in A(a, a2) where a2 references a. MySQL will report error 1451.
(2) The update statements updates multiple tables. An error occurs if there are references between the tables being updated. For example, in update A, B set A.a = 1, B.a = 2;, if A.a references B.a, B may be updated twice: first by the update statement and then by the foreign key cascade update. MySQL does not report an error in this scenario.
Fast Reproduce Steps(Required)
Steps to reproduce the behavior:
Use sys tenant and test database, execute the following sql:
alter system set _enable_defensive_check = '2';
alter system set_tp tp_no = 302, error_code = 1, frequency = 1;
CREATE TABLE `t1` (
`c1` int(11) NOT NULL,
`c2` int(11) DEFAULT NULL,
`v2` varchar(20) DEFAULT 'abc',
PRIMARY KEY (`c1`),
CONSTRAINT `t1_OBFK_1697870989172722` FOREIGN KEY (`c2`) REFERENCES `test`.`t1`(`c1`) ON UPDATE CASCADE ON DELETE CASCADE
) ;
insert into t1 values(1,1,'abc');
insert into t1 values(10,1,'abc');
update t1 set c1 = 100;
Expected behavior
In mysql, the update statement should result in the error ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails.
Actual Behavior
Oceanbase returns error -4377.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.