From 9ee2cee69aefa5f76cc73a8864c3283dd080d70a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Nov 2002 22:33:33 +0200 Subject: [PATCH] multi-delete with subselects (SCRUM) mysql-test/r/subselect.result: Multi-delete with subselect test mysql-test/t/subselect.test: Multi-delete with subselect test sql/sql_parse.cc: multi-delete with subselects --- mysql-test/r/subselect.result | 27 +++++++++++++++++++++++++++ mysql-test/t/subselect.test | 15 +++++++++++++++ sql/sql_parse.cc | 4 +++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index ce5e7d2032f..3bcb74af066 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -353,6 +353,33 @@ a b 0 10 1 11 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 t2 (a int); insert into t2 values (1); diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 4dea1ab5bca..9d332665695 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -226,6 +226,21 @@ delete from t1 where b = (select b from t2 where t1.a = t2.a); select * from t1; 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 CREATE TABLE t1 (x int); create table t2 (a int); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 86333552837..e1cf553b5a5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2095,10 +2095,12 @@ mysql_execute_command(THD *thd) /* Fix tables-to-be-deleted-from list to point at opened tables */ for (auxi=(TABLE_LIST*) aux_tables ; auxi ; auxi=auxi->next) auxi->table= auxi->table_list->table; + fix_tables_pointers(&lex->select_lex); if (!thd->fatal_error && (result= new multi_delete(thd,aux_tables, 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, (ORDER *)NULL,(ORDER *)NULL,(Item *)NULL, (ORDER *)NULL,