1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

MDEV-33988 DELETE single table to support table aliases

Gain MySQL compatibility by allowing table aliases in a single
table statement.

This now supports the syntax of:

DELETE [delete_opts] FROM tbl_name [[AS] tbl_alias] [PARTITION (partition_name [, partition_name] ...)] ....

The delete.test is from MySQL commit 1a72b69778a9791be44525501960b08856833b8d
/ Change-Id: Iac3a2b5ed993f65b7f91acdfd60013c2344db5c0.

Co-Author: Gleb Shchepa <gleb.shchepa@oracle.com> (for delete.test)

Reviewed by Igor Babaev (igor@mariadb.com)
This commit is contained in:
Daniel Black
2024-05-01 12:51:53 +10:00
parent 0cd20e3aaf
commit 75d354a23a
8 changed files with 241 additions and 12 deletions

View File

@ -334,3 +334,74 @@ c1 c2 c3
2 1 4
deallocate prepare stmt;
drop table t1,t2;
# End of 11.1
#
# MDEV-33988 DELETE (single table) to support table aliases
#
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,5,7), (3,5,8);
create table t2 (id int auto_increment primary key, a int, key(a));
insert into t2(a) values (3), (5), (-1);
# 1. The alias in delete coincides with the table name in IN subquery.
explain extended
delete from t1 t2 where t2.c1 in (select a from t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 8 100.00 Using where
1 PRIMARY t2 ref a a 5 test.t2.c1 1 100.00 Using index; FirstMatch(t2)
Warnings:
Note 1003 delete from `test`.`t1` `t2` using (`test`.`t2`) where `test`.`t2`.`a` = `test`.`t2`.`c1`
delete from t1 t2 where t2.c1 in (select a from t2);
select * from t1;
c1 c2 c3
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
2 5 7
# 2. The alias in delete is different from the alias in IN subquery
explain extended
delete from t1 t_x where t_x.c2 IN (select a from t2 as t_y);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t_x ALL NULL NULL NULL NULL 7 100.00 Using where
1 PRIMARY t_y ref a a 5 test.t_x.c2 1 100.00 Using index; FirstMatch(t_x)
Warnings:
Note 1003 delete from `test`.`t1` `t_x` using (`test`.`t2` `t_y`) where `test`.`t_y`.`a` = `test`.`t_x`.`c2`
delete from t1 t_x where t_x.c2 IN (select a from t2 as t_y);
select * from t1;
c1 c2 c3
1 1 1
1 2 2
2 1 4
2 2 5
# 3. The alias in delete is the same as the alias in IN subquery.
explain extended
delete from t1 as t_x where t_x.c3 IN (select a from t2 t_x);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t_x ALL NULL NULL NULL NULL 4 100.00 Using where
1 PRIMARY t_x ref a a 5 test.t_x.c3 1 100.00 Using index; FirstMatch(t_x)
Warnings:
Note 1003 delete from `test`.`t1` `t_x` using (`test`.`t2` `t_x`) where `test`.`t_x`.`a` = `test`.`t_x`.`c3`
delete from t1 as t_x where t_x.c3 IN (select a from t2 t_x);
select * from t1;
c1 c2 c3
1 1 1
1 2 2
2 1 4
# 4. The table in delete is the alias in IN subquery
explain extended
delete from t1 t2 where t2.c1 IN (select a -1 from t2 as t1);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY t1 index NULL a 5 NULL 3 33.33 Using where; Using index; FirstMatch(t2)
Warnings:
Note 1003 delete from `test`.`t1` `t2` using (`test`.`t2` `t1`) where `test`.`t2`.`c1` = `test`.`t1`.`a` - 1
delete from t1 t2 where t2.c1 IN (select a -1 from t2 as t1);
select * from t1;
c1 c2 c3
1 1 1
1 2 2
drop table t1, t2;
# End of 11.6