Commit 1ff79b61 authored by unknown's avatar unknown

Closing tables during SP execution the proper way.


mysql-test/r/show_check.result:
  proc table now shows up in different places.
mysql-test/r/status.result:
  proc table now shows up in different places.
sql/sp.cc:
  Fixed closing of tables.
sql/sp_head.cc:
  Close tables after each sub statement.
sql/sql_class.cc:
  Removed closing of tables in various send_eof() methods again.
parent aecc6a21
...@@ -127,6 +127,7 @@ insert into t1 values (1); ...@@ -127,6 +127,7 @@ insert into t1 values (1);
show open tables; show open tables;
Database Table In_use Name_locked Database Table In_use Name_locked
test t1 0 0 test t1 0 0
mysql proc 0 0
drop table t1; 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; 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; show create table t1;
......
...@@ -14,6 +14,6 @@ update t1 set n = 3; ...@@ -14,6 +14,6 @@ update t1 set n = 3;
unlock tables; unlock tables;
show status like 'Table_lock%'; show status like 'Table_lock%';
Variable_name Value Variable_name Value
Table_locks_immediate 3 Table_locks_immediate 4
Table_locks_waited 1 Table_locks_waited 1
drop table t1; drop table t1;
...@@ -50,13 +50,16 @@ db_find_routine_aux(THD *thd, int type, char *name, uint namelen, ...@@ -50,13 +50,16 @@ db_find_routine_aux(THD *thd, int type, char *name, uint namelen,
tables.db= (char*)"mysql"; tables.db= (char*)"mysql";
tables.real_name= tables.alias= (char*)"proc"; tables.real_name= tables.alias= (char*)"proc";
if (! (table= open_ltable(thd, &tables, ltype))) if (! (table= open_ltable(thd, &tables, ltype)))
{
*tablep= NULL;
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
}
if (table->file->index_read_idx(table->record[0], 0, if (table->file->index_read_idx(table->record[0], 0,
key, keylen, key, keylen,
HA_READ_KEY_EXACT)) HA_READ_KEY_EXACT))
{ {
close_thread_tables(thd); *tablep= NULL;
DBUG_RETURN(SP_KEY_NOT_FOUND); DBUG_RETURN(SP_KEY_NOT_FOUND);
} }
*tablep= table; *tablep= table;
...@@ -94,7 +97,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) ...@@ -94,7 +97,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp)
*sphp= tmplex->sphead; *sphp= tmplex->sphead;
done: done:
if (ret != SP_OK && table) if (table)
close_thread_tables(thd); close_thread_tables(thd);
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -129,8 +132,7 @@ db_create_routine(THD *thd, int type, ...@@ -129,8 +132,7 @@ db_create_routine(THD *thd, int type,
ret= SP_OK; ret= SP_OK;
} }
if (ret == SP_OK && table) close_thread_tables(thd);
close_thread_tables(thd);
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -149,8 +151,7 @@ db_drop_routine(THD *thd, int type, char *name, uint namelen) ...@@ -149,8 +151,7 @@ db_drop_routine(THD *thd, int type, char *name, uint namelen)
ret= SP_DELETE_ROW_FAILED; ret= SP_DELETE_ROW_FAILED;
} }
if (ret == SP_OK && table) close_thread_tables(thd);
close_thread_tables(thd);
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -251,12 +252,13 @@ bool ...@@ -251,12 +252,13 @@ bool
sp_function_exists(THD *thd, LEX_STRING *name) sp_function_exists(THD *thd, LEX_STRING *name)
{ {
TABLE *table; TABLE *table;
bool ret= FALSE;
if (db_find_routine_aux(thd, TYPE_ENUM_FUNCTION, if (db_find_routine_aux(thd, TYPE_ENUM_FUNCTION,
name->str, name->length, TL_READ, &table) == SP_OK) name->str, name->length, TL_READ, &table) == SP_OK)
{ {
close_thread_tables(thd); ret= TRUE;
return TRUE;
} }
return FALSE; close_thread_tables(thd);
return ret;
} }
...@@ -415,6 +415,11 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) ...@@ -415,6 +415,11 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
thd->lex.thd = thd; thd->lex.thd = thd;
res= mysql_execute_command(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 memcpy(&thd->lex, &olex, sizeof(LEX)); // Restore the other lex
......
...@@ -801,15 +801,6 @@ void select_export::send_error(uint errcode, const char *err) ...@@ -801,15 +801,6 @@ void select_export::send_error(uint errcode, const char *err)
bool select_export::send_eof() 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)); int error=test(end_io_cache(&cache));
if (my_close(file,MYF(MY_WME))) if (my_close(file,MYF(MY_WME)))
error=1; error=1;
...@@ -920,15 +911,6 @@ void select_dump::send_error(uint errcode,const char *err) ...@@ -920,15 +911,6 @@ void select_dump::send_error(uint errcode,const char *err)
bool select_dump::send_eof() 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)); int error=test(end_io_cache(&cache));
if (my_close(file,MYF(MY_WME))) if (my_close(file,MYF(MY_WME)))
error=1; error=1;
...@@ -1061,15 +1043,6 @@ bool select_dumpvar::send_data(List<Item> &items) ...@@ -1061,15 +1043,6 @@ bool select_dumpvar::send_data(List<Item> &items)
bool select_dumpvar::send_eof() 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) if (row_count)
{ {
::send_ok(thd,row_count); ::send_ok(thd,row_count);
......
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