diff options
-rw-r--r-- | mysql-test/r/sp.result | 10 | ||||
-rw-r--r-- | mysql-test/t/sp.test | 23 | ||||
-rw-r--r-- | sql/sp.cc | 13 |
3 files changed, 42 insertions, 4 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index daad032b854..cb0ae310ceb 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -2779,4 +2779,14 @@ a 3.2000 drop procedure bug8937| delete from t1| +drop procedure if exists bug9566| +create procedure bug9566() +begin +select * from t1; +end| +lock table t1 read| +call bug9566()| +ERROR HY000: Table 'proc' was not locked with LOCK TABLES +unlock tables| +drop procedure bug9566| drop table t1,t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index a741a4af7d8..799e88a6615 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -3397,6 +3397,29 @@ call bug8937()| drop procedure bug8937| delete from t1| +# +# BUG#9566: explicit LOCK TABLE and store procedures result in illegal state +# +# We should not think that mysql.proc table does not exist if we are unable +# to open it under LOCK TABLE or in prelocked mode. Probably this test +# should be removed when Monty will allow access to mysql.proc without +# locking it. +# +--disable_warnings +drop procedure if exists bug9566| +--enable_warnings +create procedure bug9566() +begin + select * from t1; +end| +lock table t1 read| +# This should fail because we forgot to lock mysql.proc table explicitly +--error 1100 +call bug9566()| +unlock tables| +# This should succeed +drop procedure bug9566| + # # BUG#NNNN: New bug synopsis diff --git a/sql/sp.cc b/sql/sp.cc index 23d389cd299..1956f32f2c6 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -70,9 +70,8 @@ db_find_routine_aux(THD *thd, int type, sp_name *name, type, name->m_name.length, name->m_name.str)); /* - Speed up things if mysql.proc doesn't exists - mysql_proc_table_exists is set when on creates a stored procedure - or on flush privileges + Speed up things if mysql.proc doesn't exists. mysql_proc_table_exists + is set when we create or read stored procedure or on flush privileges. */ if (!mysql_proc_table_exists && ltype == TL_READ) DBUG_RETURN(SP_OPEN_TABLE_FAILED); @@ -98,7 +97,13 @@ db_find_routine_aux(THD *thd, int type, sp_name *name, if (! (table= open_ltable(thd, &tables, ltype))) { *tablep= NULL; - mysql_proc_table_exists= 0; + /* + Under explicit LOCK TABLES or in prelocked mode we should not + say that mysql.proc table does not exist if we are unable to + open it since this condition may be transient. + */ + if (!(thd->locked_tables || thd->prelocked_mode)) + mysql_proc_table_exists= 0; DBUG_RETURN(SP_OPEN_TABLE_FAILED); } *opened= TRUE; |