[MDEV-30378] Versioned REPLACE succeeds with ON DELETE RESTRICT constraint Created: 2023-01-10  Updated: 2023-09-21  Resolved: 2023-01-12

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB, Versioned Tables
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11
Fix Version/s: 10.11.2, 10.3.38, 10.4.28, 10.5.19, 10.6.12, 10.7.8, 10.8.8, 10.9.5, 10.10.3

Type: Bug Priority: Critical
Reporter: Nikita Malyavin Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-29181 Potential corruption on Foreign key u... In Review
Relates
relates to MDEV-32221 SIGSEGV in ha_innobase::update_row, U... Open

 Description   

The following test succeeds, but shouldn't:

--source include/have_innodb.inc
 
CREATE TABLE t0 (pk integer primary key) WITH SYSTEM VERSIONING ENGINE=innodb ;
CREATE TABLE t1 (pk integer primary key REFERENCES t0(pk) 
                          ON DELETE RESTRICT ON UPDATE CASCADE)  ENGINE=innodb ;
CREATE TABLE t2 (pk integer)  ENGINE=innodb ;
 
INSERT INTO t0 (pk) VALUES (1) ;
INSERT INTO t1 (pk) VALUES (1) ;
INSERT INTO t2 (pk) VALUES (1) ;
# ALTER TABLE t1 ADD FOREIGN KEY (pk)  ;
# FLUSH TABLES;
--error ER_ROW_IS_REFERENCED_2
DELETE FROM t0;
 
--echo # Succeeds!
REPLACE t0 values (1);
 
SELECT * FROM t0 INTO OUTFILE 'load_table1_innodb_int_autoinc';
--echo # Also succeeds!
LOAD DATA INFILE 'load_table1_innodb_int_autoinc' REPLACE INTO TABLE t0;
 
DELETE t0, t2 FROM t0 join t2;
select pk as `empty!` from t0;
 
 
DROP TABLE t1, t0, t2;

Here, the referential constraint forbids deleting. However, it succeeds for operations that do deletion, other than single-table delete

The expected behavior is: REPLACE, multi-DELETE and LOAD DATA...REPLACE fail with ER_ROW_IS_REFERENCED_2.



 Comments   
Comment by Nikita Malyavin [ 2023-01-11 ]

Patch for review

Generated at Thu Feb 08 10:15:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.