Commit d4933af8 authored by unknown's avatar unknown

BUG#21414: SP: Procedure undroppable, to some extent

The problem was that if after FLUSH TABLES WITH READ LOCK the user
issued DROP/ALTER PROCEDURE/FUNCTION the operation would fail (as
expected), but after UNLOCK TABLE any attempt to execute the same
operation would lead to the error 1305 "PROCEDURE/FUNCTION does not
exist", and an attempt to execute any stored function will also fail.

This happened because under FLUSH TABLES WITH READ LOCK we couldn't open
and lock mysql.proc table for update, and this fact was erroneously
remembered by setting mysql_proc_table_exists to false, so subsequent
statements believed that mysql.proc doesn't exist, and thus that there
are no functions and procedures in the database.

As a solution, we remove mysql_proc_table_exists flag completely.  The
reason is that this optimization didn't work most of the time anyway.
Even if open of mysql.proc failed for some reason when we were trying to
call a function or a procedure, we were setting mysql_proc_table_exists
back to true to force table reopen for the sake of producing the same
error message (the open can fail for number of reasons).  The solution
could have been to remember the reason why open failed, but that's a lot
of code for optimization of a rare case.  Hence we simply remove this
optimization.


mysql-test/r/sp.result:
  Add result for bug#21414: SP: Procedure undroppable, to some extent.
mysql-test/t/sp.test:
  Remove no longer relevant comment.
  Add test case for bug#21414: SP: Procedure undroppable, to some extent.
sql/mysql_priv.h:
  Remove declaration of mysql_proc_table_exists.
sql/sp.cc:
  Remove references to mysql_proc_table_exists.
sql/sql_acl.cc:
  Remove reference to mysql_proc_table_exists.
parent 33294b1b
...@@ -5394,4 +5394,12 @@ Procedure sql_mode Create Procedure ...@@ -5394,4 +5394,12 @@ Procedure sql_mode Create Procedure
bug21416 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug21416`() bug21416 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug21416`()
show create procedure bug21416 show create procedure bug21416
drop procedure bug21416| drop procedure bug21416|
DROP PROCEDURE IF EXISTS bug21414|
CREATE PROCEDURE bug21414() SELECT 1|
FLUSH TABLES WITH READ LOCK|
DROP PROCEDURE bug21414|
ERROR HY000: Can't execute the query because you have a conflicting read lock
UNLOCK TABLES|
The following should succeed.
DROP PROCEDURE bug21414|
drop table t1,t2; drop table t1,t2;
# #
# Basic stored PROCEDURE tests # Basic stored PROCEDURE tests
# #
# Please keep this file free of --error cases and other
# things that will not run in a single debugged mysqld
# process (e.g. master-slave things).
#
# Test cases for bugs are added at the end. See template there. # Test cases for bugs are added at the end. See template there.
# #
# Tests that require --error go into sp-error.test # Some tests that require --error go into sp-error.test
# Tests that require inndb go into sp_trans.test # Tests that require inndb go into sp_trans.test
# Tests that check privilege and security issues go to sp-security.test. # Tests that check privilege and security issues go to sp-security.test.
# Tests that require multiple connections, except security/privilege tests, # Tests that require multiple connections, except security/privilege tests,
...@@ -6322,6 +6318,27 @@ create procedure bug21416() show create procedure bug21416| ...@@ -6322,6 +6318,27 @@ create procedure bug21416() show create procedure bug21416|
call bug21416()| call bug21416()|
drop procedure bug21416| drop procedure bug21416|
#
# BUG#21414: SP: Procedure undroppable, to some extent
#
--disable_warnings
DROP PROCEDURE IF EXISTS bug21414|
--enable_warnings
CREATE PROCEDURE bug21414() SELECT 1|
FLUSH TABLES WITH READ LOCK|
--error ER_CANT_UPDATE_WITH_READLOCK
DROP PROCEDURE bug21414|
UNLOCK TABLES|
--echo The following should succeed.
DROP PROCEDURE bug21414|
# #
# BUG#NNNN: New bug synopsis # BUG#NNNN: New bug synopsis
# #
......
...@@ -1216,7 +1216,6 @@ extern my_bool opt_log_queries_not_using_indexes; ...@@ -1216,7 +1216,6 @@ extern my_bool opt_log_queries_not_using_indexes;
extern bool opt_disable_networking, opt_skip_show_db; extern bool opt_disable_networking, opt_skip_show_db;
extern my_bool opt_character_set_client_handshake; extern my_bool opt_character_set_client_handshake;
extern bool volatile abort_loop, shutdown_in_progress, grant_option; extern bool volatile abort_loop, shutdown_in_progress, grant_option;
extern bool mysql_proc_table_exists;
extern uint volatile thread_count, thread_running, global_read_lock; extern uint volatile thread_count, thread_running, global_read_lock;
extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types; extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
extern my_bool opt_safe_show_db, opt_local_infile; extern my_bool opt_safe_show_db, opt_local_infile;
......
...@@ -66,8 +66,6 @@ enum ...@@ -66,8 +66,6 @@ enum
MYSQL_PROC_FIELD_COUNT MYSQL_PROC_FIELD_COUNT
}; };
bool mysql_proc_table_exists= 1;
/* Tells what SP_DEFAULT_ACCESS should be mapped to */ /* Tells what SP_DEFAULT_ACCESS should be mapped to */
#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL #define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
...@@ -119,13 +117,6 @@ TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup) ...@@ -119,13 +117,6 @@ TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
bool not_used; bool not_used;
DBUG_ENTER("open_proc_table"); DBUG_ENTER("open_proc_table");
/*
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)
DBUG_RETURN(0);
thd->reset_n_backup_open_tables_state(backup); thd->reset_n_backup_open_tables_state(backup);
bzero((char*) &tables, sizeof(tables)); bzero((char*) &tables, sizeof(tables));
...@@ -135,7 +126,6 @@ TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup) ...@@ -135,7 +126,6 @@ TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
MYSQL_LOCK_IGNORE_FLUSH))) MYSQL_LOCK_IGNORE_FLUSH)))
{ {
thd->restore_backup_open_tables_state(backup); thd->restore_backup_open_tables_state(backup);
mysql_proc_table_exists= 0;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -184,15 +174,6 @@ static TABLE *open_proc_table_for_update(THD *thd) ...@@ -184,15 +174,6 @@ static TABLE *open_proc_table_for_update(THD *thd)
table= open_ltable(thd, &tables, TL_WRITE); table= open_ltable(thd, &tables, TL_WRITE);
/*
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 and lock it for writing since this condition may be
transient.
*/
if (!(thd->locked_tables || thd->prelocked_mode) || table)
mysql_proc_table_exists= test(table);
DBUG_RETURN(table); DBUG_RETURN(table);
} }
...@@ -1610,14 +1591,6 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex, ...@@ -1610,14 +1591,6 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
case SP_KEY_NOT_FOUND: case SP_KEY_NOT_FOUND:
ret= SP_OK; ret= SP_OK;
break; break;
case SP_OPEN_TABLE_FAILED:
/*
Force it to attempt opening it again on subsequent calls;
otherwise we will get one error message the first time, and
then ER_SP_PROC_TABLE_CORRUPT (below) on subsequent tries.
*/
mysql_proc_table_exists= 1;
/* Fall through */
default: default:
/* /*
Any error when loading an existing routine is either some problem Any error when loading an existing routine is either some problem
......
...@@ -202,7 +202,6 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) ...@@ -202,7 +202,6 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
DBUG_ENTER("acl_load"); DBUG_ENTER("acl_load");
grant_version++; /* Privileges updated */ grant_version++; /* Privileges updated */
mysql_proc_table_exists= 1; // Assume mysql.proc exists
acl_cache->clear(1); // Clear locked hostname cache acl_cache->clear(1); // Clear locked hostname cache
......
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