From a6a589ef76b5042b5567ac45f58c6fa798986247 Mon Sep 17 00:00:00 2001 From: "acurtis@xiphis.org" <> Date: Tue, 24 May 2005 11:44:34 +0100 Subject: [PATCH] Bug#7241 - Invalid response when DELETE .. USING and LOCK TABLES used. Only acquire necessary write lock for multi-delete --- mysql-test/r/lock.result | 10 ++++++++++ mysql-test/t/lock.test | 14 ++++++++++++++ sql/sql_parse.cc | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/mysql-test/r/lock.result b/mysql-test/r/lock.result index 429bc5ed352..54162a36d83 100644 --- a/mysql-test/r/lock.result +++ b/mysql-test/r/lock.result @@ -47,3 +47,13 @@ unlock tables; lock tables t1 write, t1 as t1_alias read; insert into t1 select index1,nr from t1 as t1_alias; drop table t1,t2; +create table t1 ( a int(11) not null auto_increment, primary key(a)); +create table t2 ( a int(11) not null auto_increment, primary key(a)); +lock tables t1 write, t2 read; +delete from t1 using t1,t2 where t1.a=t2.a; +delete t1 from t1,t2 where t1.a=t2.a; +delete from t2 using t1,t2 where t1.a=t2.a; +ERROR HY000: Table 't2' was locked with a READ lock and can't be updated +delete t2 from t1,t2 where t1.a=t2.a; +ERROR HY000: Table 't2' was locked with a READ lock and can't be updated +drop table t1,t2; diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test index 26fc4e32bda..261c01b405c 100644 --- a/mysql-test/t/lock.test +++ b/mysql-test/t/lock.test @@ -59,3 +59,17 @@ unlock tables; lock tables t1 write, t1 as t1_alias read; insert into t1 select index1,nr from t1 as t1_alias; drop table t1,t2; + +# +# Bug7241 - Invalid response when DELETE .. USING and LOCK TABLES used. +# +create table t1 ( a int(11) not null auto_increment, primary key(a)); +create table t2 ( a int(11) not null auto_increment, primary key(a)); +lock tables t1 write, t2 read; +delete from t1 using t1,t2 where t1.a=t2.a; +delete t1 from t1,t2 where t1.a=t2.a; +--error 1099 +delete from t2 using t1,t2 where t1.a=t2.a; +--error 1099 +delete t2 from t1,t2 where t1.a=t2.a; +drop table t1,t2; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c5b429ec8fc..2c1723be5d9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4141,6 +4141,7 @@ void mysql_init_multi_delete(LEX *lex) lex->select_lex.select_limit= lex->unit.select_limit_cnt= HA_POS_ERROR; lex->select_lex.table_list.save_and_clear(&lex->auxilliary_table_list); + lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ; } @@ -5437,6 +5438,11 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) } walk->lock_type= target_tbl->lock_type; target_tbl->table_list= walk; // Remember corresponding table + if (walk->table_list) + { + target_tbl->table_list= walk->table_list; + walk->table_list->lock_type= walk->lock_type; + } } DBUG_RETURN(0); }