[MDEV-24990] Delete with table name on system versioned table with cascading delete fails Created: 2021-02-25  Updated: 2023-07-20  Resolved: 2023-07-20

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Delete, Versioned Tables
Affects Version/s: 10.3.27, 10.3, 10.4, 10.5
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Ryan Stark Assignee: Aleksey Midenkov
Resolution: Cannot Reproduce Votes: 0
Labels: None
Environment:

10.3.27-MariaDB-0+deb10u1


Attachments: File script to reproduce.sql    

 Description   

Version 10.3.27 on Debian tested, have not tested other platforms.

Create two tables, both with system versioning. Table one has some random records in it. Table two has a foreign key reference to table one with a cascading delete. Create some records.

Running a delete query of the format "DELETE table1 FROM table1" does not cascade the deletion to table2 while the query "DELETE FROM table1" does cascade as expected.

--source include/have_innodb.inc
 
create table t1 (
	id tinyint unsigned not null auto_increment,
	value char(1),
	primary key ( id )
) engine=innodb with system versioning;
create table t2 (
	parent tinyint unsigned not null,
	foreign key ( parent ) references t1 ( id ) on update cascade on delete cascade
) engine=innodb with system versioning;
 
insert into t1 (value) values ('a'), ('b');
insert into t2 values (1), (2);
 
delete from t1 where id = 1;
delete t1 from t1 where id = 2;
select * from t1;
 
drop tables t2, t1;



 Comments   
Comment by Alice Sherepa [ 2021-02-26 ]

Thanks for the report! I repeated on 10.3-10.5:

10.5

MariaDB [test]> create table test1 (id int not null primary key,value char(1)
    -> )engine=innodb with system versioning;
Query OK, 0 rows affected (0.109 sec)
 
MariaDB [test]> insert into test1 values (1,'a'),(2,'b');
Query OK, 2 rows affected (0.006 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> create table test2 (
    -> parent int not null,
    -> foreign key ( parent ) references test1 ( id ) on update cascade on delete cascade
    -> )engine=innodb;
Query OK, 0 rows affected (0.048 sec)
 
MariaDB [test]> insert into test2 values (1),(2);
Query OK, 2 rows affected (0.011 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> select * from test2 left join test1 on test2.parent = test1.id;
+--------+------+-------+
| parent | id   | value |
+--------+------+-------+
|      1 |    1 | a     |
|      2 |    2 | b     |
+--------+------+-------+
2 rows in set (0.018 sec)
 
MariaDB [test]> delete test1.* from test1 where id = 1;
Query OK, 1 row affected (0.008 sec)
 
MariaDB [test]> select * from test2 left join test1 on test2.parent = test1.id;
+--------+------+-------+
| parent | id   | value |
+--------+------+-------+
|      1 | NULL | NULL  |
|      2 |    2 | b     |
+--------+------+-------+
2 rows in set (0.004 sec)
 
MariaDB [test]> alter table test1 drop system versioning;
Query OK, 0 rows affected (0.073 sec)
Records: 0  Duplicates: 0  Warnings: 0
 
MariaDB [test]> delete test1.* from test1 where id = 2;
Query OK, 1 row affected (0.004 sec)
 
MariaDB [test]> select * from test2 left join test1 on test2.parent = test1.id;
+--------+------+-------+
| parent | id   | value |
+--------+------+-------+
|      1 | NULL | NULL  |
+--------+------+-------+
1 row in set (0.001 sec)

Comment by Aleksey Midenkov [ 2023-07-20 ]

Doesn't reproduce in latest 10.4, 10.5

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