Commit e419b767 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

multi-delete with subselects (SCRUM)

parent 6b403114
...@@ -353,6 +353,33 @@ a b ...@@ -353,6 +353,33 @@ a b
0 10 0 10
1 11 1 11
drop table t1, t2; drop table t1, t2;
drop table if exists t11, t12, t2;
create table t11 (a int NOT NULL, b int, primary key (a));
create table t12 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a));
insert into t11 values (0, 10),(1, 11),(2, 12);
insert into t12 values (33, 10),(22, 11),(2, 12);
insert into t2 values (1, 21),(2, 12),(3, 23);
select * from t11;
a b
0 10
1 11
2 12
select * from t12;
a b
33 10
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
select * from t11;
a b
0 10
1 11
select * from t12;
a b
33 10
22 11
drop table t11, t12, t2;
CREATE TABLE t1 (x int); CREATE TABLE t1 (x int);
create table t2 (a int); create table t2 (a int);
insert into t2 values (1); insert into t2 values (1);
......
...@@ -226,6 +226,21 @@ delete from t1 where b = (select b from t2 where t1.a = t2.a); ...@@ -226,6 +226,21 @@ delete from t1 where b = (select b from t2 where t1.a = t2.a);
select * from t1; select * from t1;
drop table t1, t2; drop table t1, t2;
#multi-delete with subselects
drop table if exists t11, t12, t2;
create table t11 (a int NOT NULL, b int, primary key (a));
create table t12 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a));
insert into t11 values (0, 10),(1, 11),(2, 12);
insert into t12 values (33, 10),(22, 11),(2, 12);
insert into t2 values (1, 21),(2, 12),(3, 23);
select * from t11;
select * from t12;
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
select * from t11;
select * from t12;
drop table t11, t12, t2;
#insert with subselects #insert with subselects
CREATE TABLE t1 (x int); CREATE TABLE t1 (x int);
create table t2 (a int); create table t2 (a int);
......
...@@ -2095,10 +2095,12 @@ mysql_execute_command(THD *thd) ...@@ -2095,10 +2095,12 @@ mysql_execute_command(THD *thd)
/* Fix tables-to-be-deleted-from list to point at opened tables */ /* Fix tables-to-be-deleted-from list to point at opened tables */
for (auxi=(TABLE_LIST*) aux_tables ; auxi ; auxi=auxi->next) for (auxi=(TABLE_LIST*) aux_tables ; auxi ; auxi=auxi->next)
auxi->table= auxi->table_list->table; auxi->table= auxi->table_list->table;
fix_tables_pointers(&lex->select_lex);
if (!thd->fatal_error && (result= new multi_delete(thd,aux_tables, if (!thd->fatal_error && (result= new multi_delete(thd,aux_tables,
table_count))) table_count)))
{ {
res= mysql_select(thd,tables,select_lex->item_list, res= mysql_select(thd,select_lex->get_table_list(),
select_lex->item_list,
select_lex->where, select_lex->where,
(ORDER *)NULL,(ORDER *)NULL,(Item *)NULL, (ORDER *)NULL,(ORDER *)NULL,(Item *)NULL,
(ORDER *)NULL, (ORDER *)NULL,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment