summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/show_check.result1
-rw-r--r--mysql-test/r/status.result2
-rw-r--r--sql/sp.cc20
-rw-r--r--sql/sp_head.cc5
-rw-r--r--sql/sql_class.cc27
5 files changed, 18 insertions, 37 deletions
diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result
index de652b05154..c5e7ca154df 100644
--- a/mysql-test/r/show_check.result
+++ b/mysql-test/r/show_check.result
@@ -127,6 +127,7 @@ insert into t1 values (1);
show open tables;
Database Table In_use Name_locked
test t1 0 0
+mysql proc 0 0
drop table t1;
create table t1 (a int not null, b VARCHAR(10), INDEX (b) ) AVG_ROW_LENGTH=10 CHECKSUM=1 COMMENT="test" TYPE=MYISAM MIN_ROWS=10 MAX_ROWS=100 PACK_KEYS=1 DELAY_KEY_WRITE=1 ROW_FORMAT=fixed;
show create table t1;
diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result
index 3ef6cec32b3..f93147d00c5 100644
--- a/mysql-test/r/status.result
+++ b/mysql-test/r/status.result
@@ -14,6 +14,6 @@ update t1 set n = 3;
unlock tables;
show status like 'Table_lock%';
Variable_name Value
-Table_locks_immediate 3
+Table_locks_immediate 4
Table_locks_waited 1
drop table t1;
diff --git a/sql/sp.cc b/sql/sp.cc
index f7b8cf235ca..52d59eb1a3e 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -50,13 +50,16 @@ db_find_routine_aux(THD *thd, int type, char *name, uint namelen,
tables.db= (char*)"mysql";
tables.real_name= tables.alias= (char*)"proc";
if (! (table= open_ltable(thd, &tables, ltype)))
+ {
+ *tablep= NULL;
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
+ }
if (table->file->index_read_idx(table->record[0], 0,
key, keylen,
HA_READ_KEY_EXACT))
{
- close_thread_tables(thd);
+ *tablep= NULL;
DBUG_RETURN(SP_KEY_NOT_FOUND);
}
*tablep= table;
@@ -94,7 +97,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp)
*sphp= tmplex->sphead;
done:
- if (ret != SP_OK && table)
+ if (table)
close_thread_tables(thd);
DBUG_RETURN(ret);
}
@@ -129,8 +132,7 @@ db_create_routine(THD *thd, int type,
ret= SP_OK;
}
- if (ret == SP_OK && table)
- close_thread_tables(thd);
+ close_thread_tables(thd);
DBUG_RETURN(ret);
}
@@ -149,8 +151,7 @@ db_drop_routine(THD *thd, int type, char *name, uint namelen)
ret= SP_DELETE_ROW_FAILED;
}
- if (ret == SP_OK && table)
- close_thread_tables(thd);
+ close_thread_tables(thd);
DBUG_RETURN(ret);
}
@@ -251,12 +252,13 @@ bool
sp_function_exists(THD *thd, LEX_STRING *name)
{
TABLE *table;
+ bool ret= FALSE;
if (db_find_routine_aux(thd, TYPE_ENUM_FUNCTION,
name->str, name->length, TL_READ, &table) == SP_OK)
{
- close_thread_tables(thd);
- return TRUE;
+ ret= TRUE;
}
- return FALSE;
+ close_thread_tables(thd);
+ return ret;
}
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index b461f2035ad..9de3ee471f2 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -415,6 +415,11 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
thd->lex.thd = thd;
res= mysql_execute_command(thd);
+ if (thd->lock || thd->open_tables || thd->derived_tables)
+ {
+ thd->proc_info="closing tables";
+ close_thread_tables(thd); /* Free tables */
+ }
memcpy(&thd->lex, &olex, sizeof(LEX)); // Restore the other lex
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index ac82996600f..5ac904393f5 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -801,15 +801,6 @@ void select_export::send_error(uint errcode, const char *err)
bool select_export::send_eof()
{
- /* This mimics select_send::send_eof(), which unlocks this way.
- * It appears to be necessary, since tables aren't unlock after
- * selects otherwise.
- */
- if (thd->lock)
- {
- mysql_unlock_tables(thd, thd->lock);
- thd->lock=0;
- }
int error=test(end_io_cache(&cache));
if (my_close(file,MYF(MY_WME)))
error=1;
@@ -920,15 +911,6 @@ void select_dump::send_error(uint errcode,const char *err)
bool select_dump::send_eof()
{
- /* This mimics select_send::send_eof(), which unlocks this way.
- * It appears to be necessary, since tables aren't unlock after
- * selects otherwise.
- */
- if (thd->lock)
- {
- mysql_unlock_tables(thd, thd->lock);
- thd->lock=0;
- }
int error=test(end_io_cache(&cache));
if (my_close(file,MYF(MY_WME)))
error=1;
@@ -1061,15 +1043,6 @@ bool select_dumpvar::send_data(List<Item> &items)
bool select_dumpvar::send_eof()
{
- /* This mimics select_send::send_eof(), which unlocks this way.
- * It appears to be necessary, since tables aren't unlock after
- * selects otherwise.
- */
- if (thd->lock)
- {
- mysql_unlock_tables(thd, thd->lock);
- thd->lock=0;
- }
if (row_count)
{
::send_ok(thd,row_count);