mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-28965 Assertion failure when preparing UPDATE with derived table in WHERE
This patch fixes not only the assertion failure in the function Field_iterator_table_ref::set_field_iterator() but also: - fixes the problem of forced materialization of derived tables used in subqueries contained in WHERE clauses of single-table and multi-table UPDATE and DELETE statements - fixes the problem of MDEV-17954 that prevented execution of multi-table DELETE statements if they use in their WHERE clauses references to the tables that are updated. The patch must be considered a complement to the patch for MDEV-28883. Approved by Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
@ -135,3 +135,123 @@ set session sort_buffer_size = 1024;
|
||||
delete from t1 where c1=0 and exists(select 'x' from t1 b where b.c1<10);
|
||||
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-17954: multi-table DELETE with the same source and target
|
||||
--echo #
|
||||
|
||||
create table t1 (c1 int, c2 int, c3 int);
|
||||
insert into t1 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
|
||||
--echo #
|
||||
--echo # Single-table DELETE with the same source and target
|
||||
--echo # handled as multi-table DELETE
|
||||
--echo #
|
||||
|
||||
let $q1=
|
||||
delete from t1
|
||||
where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1 and a.c2 < 3);
|
||||
|
||||
eval explain $q1;
|
||||
eval $q1;
|
||||
select * from t1;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
eval prepare stmt from "$q1";
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
deallocate prepare stmt;
|
||||
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
|
||||
--echo #
|
||||
--echo # Multi-table DELETE with the same source and target
|
||||
--echo #
|
||||
|
||||
create table t2 (c1 int, c2 int, c3 int);
|
||||
insert into t2 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,5,8);
|
||||
|
||||
let $q2=
|
||||
delete from t1 using t1,t2
|
||||
where t1.c2 = t2.c2 and t1.c1 > 1;
|
||||
|
||||
eval explain $q2;
|
||||
eval $q2;
|
||||
select * from t1;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
eval prepare stmt from "$q2";
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
deallocate prepare stmt;
|
||||
|
||||
let $q2=
|
||||
delete from t1 using t1,t2
|
||||
where t1.c2 = t2.c2 and t1.c1 > 1;
|
||||
|
||||
eval explain $q2;
|
||||
eval $q2;
|
||||
select * from t1;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
eval prepare stmt from "$q2";
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
deallocate prepare stmt;
|
||||
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
|
||||
let $q3=
|
||||
delete from t1,t2 using t1,t2
|
||||
where t1.c2 = t2.c2 and t1.c1 > 1 and t2.c1 > 1;
|
||||
|
||||
eval explain $q3;
|
||||
eval $q3;
|
||||
select * from t1;
|
||||
select * from t2;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
delete from t2;
|
||||
insert into t2 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,5,8);
|
||||
eval prepare stmt from "$q3";
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
select * from t2;
|
||||
delete from t1;
|
||||
insert into t1 values
|
||||
(1,2,2), (1,3,3), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
|
||||
delete from t2;
|
||||
insert into t2 values
|
||||
(1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5);
|
||||
execute stmt;
|
||||
select * from t1;
|
||||
select * from t2;
|
||||
deallocate prepare stmt;
|
||||
|
||||
drop table t1,t2;
|
||||
|
Reference in New Issue
Block a user