Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-35848, MDEV-35568 Reintroduce delete_while_scanning for multi_de… #3810

Open
wants to merge 1 commit into
base: bb-11.8-mdev-30469
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions mysql-test/main/delete_multi_order_by.result
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,157 @@ update t2, t1 set t2.field=t1.field where t1.id1=t2.id2 and 0=1;
delete t1, t2 from t2 inner join t1 on t1.id1=t2.id2 where 0=1;
drop table t1, t2;
set session sql_buffer_result=default;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select * from t1;
id v
2 3
1 4
select * from t2;
id v
5 5
6 6
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 1;
id v id v
1 4 5 5
delete t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 1;
select * from t1;
id v
2 3
select * from t2;
id v
6 6
drop table t1, t2;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select * from t1;
id v
2 3
1 4
select * from t2;
id v
5 5
6 6
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
id v id v
1 4 5 5
1 4 6 6
delete t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
select * from t1;
id v
2 3
select * from t2;
id v
drop table t1, t2;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select * from t1;
id v
2 3
1 4
select * from t2;
id v
5 5
6 6
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 3;
id v id v
1 4 5 5
1 4 6 6
2 3 5 5
delete t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 3;
select * from t1;
id v
select * from t2;
id v
drop table t1, t2;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
create table t3 (id int primary key, v int);
insert into t1 (id, v) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000);
insert into t2 (id, v) values (10, 100), (20, 200), (30, 300), (40, 400), (50, 500);
insert into t3 (id, v) values (11, 111), (22, 222), (33, 333), (44, 444), (55, 555);
select * from t1;
id v
1 1000
2 2000
3 3000
4 4000
5 5000
select * from t2;
id v
10 100
20 200
30 300
40 400
50 500
select * from t3;
id v
11 111
22 222
33 333
44 444
55 555
select t1.*, t2.*, t3.* from t1, t2, t3 order by t1.id, t2.id, t3.id limit 3;
id v id v id v
1 1000 10 100 11 111
1 1000 10 100 22 222
1 1000 10 100 33 333
delete t1.*, t2.*, t3.* from t1, t2, t3 order by t1.id, t2.id, t3.id limit 3;
select * from t1;
id v
2 2000
3 3000
4 4000
5 5000
select * from t2;
id v
20 200
30 300
40 400
50 500
select * from t3;
id v
44 444
55 555
drop table t1, t2, t3;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
create table t3 (id int primary key, v int);
insert into t1 (id, v) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000);
insert into t2 (id, v) values (10, 100), (20, 200), (30, 300), (40, 400), (50, 500);
insert into t3 (id, v) values (11, 111), (22, 222), (33, 333), (44, 444), (55, 555);
select * from t1;
id v
1 1000
2 2000
3 3000
4 4000
5 5000
select * from t2;
id v
10 100
20 200
30 300
40 400
50 500
select * from t3;
id v
11 111
22 222
33 333
44 444
55 555
delete t1.*, t2.*, t3.* from t1, t2, t3;
select * from t1;
id v
select * from t2;
id v
select * from t3;
id v
drop table t1, t2, t3;
74 changes: 74 additions & 0 deletions mysql-test/main/delete_multi_order_by.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# MDEV-30469 Support ORDER BY and LIMIT for multi-table DELETE, index hints for single-table DELETE.
#

--source include/have_innodb.inc

create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (4,1),(3,2),(2,3),(1,4);
Expand Down Expand Up @@ -129,3 +132,74 @@ delete t1, t2 from t2 inner join t1 on t1.id1=t2.id2 where 0=1;

drop table t1, t2;
set session sql_buffer_result=default;

create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select * from t1;
select * from t2;
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 1;
delete t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 1;
select * from t1;
select * from t2;

drop table t1, t2;

create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select * from t1;
select * from t2;
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
delete t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
select * from t1;
select * from t2;

drop table t1, t2;

create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select * from t1;
select * from t2;
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 3;
delete t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 3;
select * from t1;
select * from t2;

drop table t1, t2;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
create table t3 (id int primary key, v int);
insert into t1 (id, v) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000);
insert into t2 (id, v) values (10, 100), (20, 200), (30, 300), (40, 400), (50, 500);
insert into t3 (id, v) values (11, 111), (22, 222), (33, 333), (44, 444), (55, 555);
select * from t1;
select * from t2;
select * from t3;
select t1.*, t2.*, t3.* from t1, t2, t3 order by t1.id, t2.id, t3.id limit 3;
delete t1.*, t2.*, t3.* from t1, t2, t3 order by t1.id, t2.id, t3.id limit 3;
select * from t1;
select * from t2;
select * from t3;

drop table t1, t2, t3;

create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
create table t3 (id int primary key, v int);
insert into t1 (id, v) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000);
insert into t2 (id, v) values (10, 100), (20, 200), (30, 300), (40, 400), (50, 500);
insert into t3 (id, v) values (11, 111), (22, 222), (33, 333), (44, 444), (55, 555);
select * from t1;
select * from t2;
select * from t3;
delete t1.*, t2.*, t3.* from t1, t2, t3;
select * from t1;
select * from t2;
select * from t3;

drop table t1, t2, t3;
4 changes: 2 additions & 2 deletions mysql-test/main/delete_single_to_multi.result
Original file line number Diff line number Diff line change
Expand Up @@ -3394,12 +3394,12 @@ o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
select o_orderkey, o_totalprice from t;
o_orderkey o_totalprice
1856 189361.42
324 26868.85
1856 189361.42
1221 117397.16
3139 40975.96
1925 146382.71
1344 43809.37
1925 146382.71
4903 34363.63
5607 24660.06
delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
Expand Down
10 changes: 4 additions & 6 deletions mysql-test/main/myisam_explain_non_select_all.result
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ Handler_read_rnd_next 4
Variable_name Value
Handler_delete 1
Handler_read_key 2
Handler_read_rnd 1
Handler_read_rnd_next 6
Handler_read_rnd_next 4

DROP TABLE t1;
#4
Expand Down Expand Up @@ -928,9 +927,9 @@ Variable_name Value
Handler_delete 8
Handler_read_key 19
Handler_read_next 3
Handler_read_rnd 8
Handler_read_rnd 5
Handler_read_rnd_deleted 1
Handler_read_rnd_next 15
Handler_read_rnd_next 11

DROP TABLE t1, t2, t3;
#20
Expand Down Expand Up @@ -1066,8 +1065,7 @@ Handler_read_rnd_next 12
Variable_name Value
Handler_delete 3
Handler_read_key 4
Handler_read_rnd 3
Handler_read_rnd_next 34
Handler_read_rnd_next 30

DROP TABLE t1, t2;
#22
Expand Down
1 change: 0 additions & 1 deletion mysql-test/suite/perfschema/r/multi_table_io.result
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ wait/io/table/sql/handler TABLE test1 t2 update 1
wait/io/table/sql/handler TABLE test marker insert 1
wait/io/table/sql/handler TABLE test t1 fetch 1
wait/io/table/sql/handler TABLE test1 t2 fetch 1
wait/io/table/sql/handler TABLE test t1 fetch 1
wait/io/table/sql/handler TABLE test t1 delete 1
wait/io/table/sql/handler TABLE test1 t2 fetch 1
wait/io/table/sql/handler TABLE test1 t2 delete 1
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -7565,7 +7565,6 @@ class multi_delete :public select_result_interceptor
TABLE_LIST *delete_tables, *table_being_deleted;
TMP_TABLE_PARAM *tmp_table_param;
TABLE **tmp_tables, *main_table;
Unique **tempfiles;
ha_rows deleted, found;
uint table_count;
int error;
Expand All @@ -7574,6 +7573,7 @@ class multi_delete :public select_result_interceptor
bool transactional_tables;
/* True if at least one table we delete from is not transactional */
bool normal_tables;
bool delete_while_scanning;
/*
error handling (rollback and binlogging) can happen in send_eof()
so that afterward abort_result_set() needs to find out that.
Expand Down
Loading