Skip to content

Commit 1e0a72a

Browse files
mariadb-lenastartsevaigorbabaev
authored andcommitted
MDEV-29390: Improve coverage for UPDATE and DELETE statements in MTR test suites
Created tests for "delete" based on update_use_source.test For the update_use_source.test tests, data recovery in the table has been changed from a rollback transaction to a complete delete and re-insert of the data with optimize table. Cases are now being checked on three engines. Added tests for update/delete with LooseScan and DuplicateWeedout optimization strategies Added tests for engine MEMORY on delete and update Added tests for multi-update with JSON_TABLE Added tests for multi-update and multi-delete for engine Connect
1 parent 9a3fd1d commit 1e0a72a

21 files changed

+22157
-997
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
create table t1 (c1 integer, c2 integer, c3 integer);
2+
3+
insert into t1(c1,c2,c3)
4+
values (1,1,1),(1,2,2),(1,3,3),
5+
(2,1,4),(2,2,5),(2,3,6),
6+
(2,4,7),(2,5,8);
7+
insert into t1 select c1+10,c2,c3+10 from t1;
8+
insert into t1 select c1+20,c2+1,c3+20 from t1;
9+
analyze table t1 persistent for all;
10+
11+
create view v1 as select * from t1 where c2=2;
12+
13+
--echo #######################################
14+
--echo # Test without any index #
15+
--echo #######################################
16+
--source include/delete_use_source_cases.inc
17+
--source include/delete_use_source_cases_non_innodb.inc
18+
19+
--echo #######################################
20+
--echo # Test with an index #
21+
--echo #######################################
22+
create index t1_c2 on t1 (c2,c1);
23+
--source include/delete_use_source_cases.inc
24+
--source include/delete_use_source_cases_non_innodb.inc
25+
26+
--echo #######################################
27+
--echo # Test with a primary key #
28+
--echo #######################################
29+
drop index t1_c2 on t1;
30+
alter table t1 add primary key (c3);
31+
--source include/delete_use_source_cases.inc
32+
--source include/delete_use_source_cases_non_innodb.inc
33+
34+
drop view v1;
35+
drop table t1;
36+
37+
--echo #
38+
--echo # Test on dynamic columns (blob)
39+
--echo #
40+
create table assets (
41+
item_name varchar(32) primary key, -- A common attribute for all items
42+
dynamic_cols blob -- Dynamic columns will be stored here
43+
);
44+
45+
INSERT INTO assets
46+
VALUES ('MariaDB T-shirt',
47+
COLUMN_CREATE('color', 'blue', 'size', 'XL'));
48+
INSERT INTO assets
49+
VALUES ('Thinkpad Laptop',
50+
COLUMN_CREATE('color', 'black', 'price', 500));
51+
INSERT INTO assets
52+
VALUES ('Fridge',
53+
COLUMN_CREATE('color', 'white', 'warranty', '5 years'));
54+
INSERT INTO assets
55+
VALUES ('Microwave',
56+
COLUMN_CREATE('warranty', '3 years'));
57+
SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
58+
FROM assets ORDER BY item_name;
59+
UPDATE assets SET dynamic_cols=COLUMN_DELETE(dynamic_cols, 'color')
60+
WHERE item_name='Fridge';
61+
SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
62+
FROM assets ORDER BY item_name;
63+
DELETE FROM assets
64+
WHERE item_name in
65+
(select b.item_name from assets b
66+
where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
67+
SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
68+
FROM assets ORDER BY item_name;
69+
DELETE FROM assets WHERE item_name='Microwave';
70+
SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
71+
FROM assets ORDER BY item_name;
72+
drop table assets ;
73+
74+
75+
--echo #
76+
--echo # Test on fulltext columns
77+
--echo #
78+
CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
79+
INSERT INTO ft2(copy) VALUES
80+
('MySQL vs MariaDB database'),
81+
('Oracle vs MariaDB database'),
82+
('PostgreSQL vs MariaDB database'),
83+
('MariaDB overview'),
84+
('Foreign keys'),
85+
('Primary keys'),
86+
('Indexes'),
87+
('Transactions'),
88+
('Triggers');
89+
90+
SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
91+
DELETE FROM ft2 WHERE MATCH(copy) AGAINST('database');
92+
SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
93+
drop table ft2;
94+
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
--echo #
2+
--echo # Delete with value from subquery on the same table
3+
--echo #
4+
5+
analyze table t1 persistent for all;
6+
7+
let $c = c1=(select a.c3 from t1 a where a.c3 = t1.c3);
8+
eval create table tmp as select * from t1 where $c;
9+
let $q = delete from t1 where $c;
10+
eval explain select * from t1 where $c;
11+
eval explain $q;
12+
--enable_info ONCE
13+
eval $q;
14+
--sorted_result
15+
select * from t1;
16+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
17+
drop table tmp;
18+
19+
--echo #
20+
--echo # Delete with EXISTS subquery over the updated table
21+
--echo # in WHERE + possibly sargable condition
22+
--echo #
23+
24+
analyze table t1 persistent for all;
25+
26+
let $c = c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
27+
eval create table tmp as select * from t1 where $c;
28+
let $q = delete from t1 where $c;
29+
eval explain select * from t1 where $c;
30+
eval explain $q;
31+
eval analyze $q;
32+
--sorted_result
33+
select * from t1;
34+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
35+
drop table tmp;
36+
37+
--echo #
38+
--echo # Delete with IN predicand over the updated table in WHERE
39+
--echo #
40+
let $c = c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
41+
eval create table tmp as select * from t1 where $c;
42+
let $q = delete from t1 where $c;
43+
eval explain select * from t1 where $c;
44+
eval explain $q;
45+
--enable_info ONCE
46+
eval $q;
47+
--sorted_result
48+
select * from t1;
49+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
50+
drop table tmp;
51+
52+
--echo #
53+
--echo # Delete with a limit - can be deleted
54+
--echo #
55+
let $c = c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
56+
eval create table tmp as select * from t1 where $c;
57+
let $q = delete from t1 where $c;
58+
eval explain select * from t1 where $c;
59+
eval explain $q;
60+
eval analyze $q;
61+
--sorted_result
62+
select * from t1;
63+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
64+
drop table tmp;
65+
66+
--echo #
67+
--echo # Delete with a limit and an order by
68+
--echo #
69+
70+
let $c = c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
71+
order by c3 desc limit 1;
72+
eval create table tmp as select * from t1 where $c;
73+
let $q = delete from t1 where $c;
74+
eval explain select * from t1 where $c;
75+
eval explain $q;
76+
--enable_info ONCE
77+
eval $q;
78+
--sorted_result
79+
select * from t1;
80+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
81+
drop table tmp;
82+
83+
--echo #
84+
--echo # Delete: 2 execution of PS
85+
--echo #
86+
87+
prepare create_tmp_stmt from
88+
"create table tmp as select * from t1
89+
where c2=(select a.c3 from t1 a where a.c3 = ?)";
90+
prepare delete_t1_stmt from
91+
"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
92+
set @a:=5;
93+
execute create_tmp_stmt using @a;
94+
execute delete_t1_stmt using @a;
95+
execute delete_t1_stmt using @a;
96+
--sorted_result
97+
select * from t1;
98+
99+
prepare insert_tmp_stmt from
100+
"insert into tmp(c1,c2,c3) select * from t1
101+
where c2=(select a.c3 from t1 a where a.c3 = ?)";
102+
set @a:=2;
103+
execute insert_tmp_stmt using @a;
104+
execute delete_t1_stmt using @a;
105+
--sorted_result
106+
select * from t1;
107+
108+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
109+
--sorted_result
110+
select * from t1;
111+
112+
drop table tmp;
113+
114+
--echo #
115+
--echo # Delete in stored procedure
116+
--echo #
117+
118+
delimiter //;
119+
create procedure sp()
120+
begin
121+
delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
122+
order by c3 desc limit 1;
123+
end
124+
//
125+
delimiter ;//
126+
127+
create table tmp as select * from t1
128+
where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
129+
order by c3 desc limit 1;
130+
CALL sp;
131+
insert into tmp(c1,c2,c3) select * from t1
132+
where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
133+
order by c3 desc limit 1;
134+
CALL sp;
135+
insert into tmp(c1,c2,c3) select * from t1
136+
where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
137+
order by c3 desc limit 1;
138+
CALL sp;
139+
--sorted_result
140+
select * from t1;
141+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
142+
drop procedure sp;
143+
drop table tmp;
144+
145+
--echo #
146+
--echo # Delete in stored function
147+
--echo #
148+
delimiter //;
149+
create function f1(IN a INT) returns int
150+
begin
151+
delete from t1 where c3 < a order by c3 limit 1;
152+
return 1;
153+
end;//
154+
delimiter ;//
155+
156+
set @a:=7;
157+
create table tmp as select * from t1 where c3 < @a
158+
order by c3 limit 1;
159+
select f1(@a);
160+
insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
161+
order by c3 limit 1;
162+
select f1(@a);
163+
--sorted_result
164+
select * from t1;
165+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
166+
drop function f1;
167+
drop table tmp;
168+
169+
--echo #
170+
--echo # Delete in trigger
171+
--echo #
172+
173+
create table t2 (c1 integer);
174+
insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
175+
176+
CREATE TABLE cnt(del integer);
177+
INSERT INTO cnt VALUES(0);
178+
179+
CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
180+
UPDATE cnt SET del=del+1;
181+
CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
182+
DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
183+
184+
CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
185+
--enable_info ONCE
186+
DELETE FROM t1 WHERE c2>=3;
187+
188+
--sorted_result
189+
select * from t1;
190+
--sorted_result
191+
SELECT * FROM t2;
192+
SELECT * FROM cnt;
193+
194+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
195+
196+
DROP TRIGGER tr1;
197+
DROP TRIGGER tr2;
198+
drop table t2, cnt, tmp;
199+
200+
--echo #
201+
--echo # Delete with a reference to view in subquery
202+
--echo #
203+
let $c = t1.c2 in ( select max(a.c2) from v1 a
204+
where a.c1 = t1.c1);
205+
eval create table tmp as select * from t1 where $c;
206+
let $q = delete from t1 where $c;
207+
eval explain select * from t1 where $c;
208+
eval explain $q;
209+
eval analyze $q;
210+
--sorted_result
211+
select * from t1;
212+
insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
213+
drop table tmp;
214+

0 commit comments

Comments
 (0)