Commit 1d6addd9 authored by unknown's avatar unknown

BUG#9998 MySQL client hangs on "USE database"

 Use open_normal_and_derived_tables instead of open_and_lock_tables when reading metadata for a table.
 Add two test cases, one for "USE database" and one for "SHOW COLUMNS FROM table"


mysql-test/r/lock_multi.result:
  Updated test results for test case for bug9998
mysql-test/r/mysql.result:
  Updated results for test case for bug9998
mysql-test/t/lock_multi.test:
  Test that "show columsn from t1" is not locked by another thread having a write lock on t1
mysql-test/t/mysql.test:
  Add test case for BUG9998
    - lock table t1 for write from mysql-test, then execute 'mysql' and call "USE test". This will test exactly what caused the bug.
sql/sql_show.cc:
  Open tables without locking when reading metadata
parent 1c7b61e3
...@@ -36,3 +36,10 @@ lock table t1 write, t2 write; ...@@ -36,3 +36,10 @@ lock table t1 write, t2 write;
drop table t2; drop table t2;
ERROR 42S02: Table 'test.t2' doesn't exist ERROR 42S02: Table 'test.t2' doesn't exist
drop table t1; drop table t1;
create table t1(a int);
lock tables t1 write;
show columns from t1;
Field Type Null Key Default Extra
a int(11) YES NULL
unlock tables;
drop table t1;
...@@ -48,3 +48,9 @@ Test 'go' command g ...@@ -48,3 +48,9 @@ Test 'go' command g
a a
1 1
drop table t1; drop table t1;
create table t1(a int);
lock tables t1 write;
database()
test
unlock tables;
drop table t1;
...@@ -94,3 +94,15 @@ connection reader; ...@@ -94,3 +94,15 @@ connection reader;
reap; reap;
connection locker; connection locker;
drop table t1; drop table t1;
#
# BUG#9998 - MySQL client hangs on USE "database"
create table t1(a int);
lock tables t1 write;
connection reader;
show columns from t1;
connection locker;
unlock tables;
drop table t1;
...@@ -30,5 +30,14 @@ select "Test 'go' command(vertical output) \G" as " "; ...@@ -30,5 +30,14 @@ select "Test 'go' command(vertical output) \G" as " ";
select "Test 'go' command \g" as " "; select "Test 'go' command \g" as " ";
--exec $MYSQL test -e 'select * from t1\g' --exec $MYSQL test -e 'select * from t1\g'
--enable_query_log --enable_query_log
drop table t1;
#
# BUG9998 - MySQL client hangs on USE "database"
#
create table t1(a int);
lock tables t1 write;
--exec $MYSQL -e 'use test; select database();'
unlock tables;
drop table t1; drop table t1;
...@@ -348,7 +348,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) ...@@ -348,7 +348,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
table_list->table_name)); table_list->table_name));
/* Only one table for now, but VIEW can involve several tables */ /* Only one table for now, but VIEW can involve several tables */
if (open_and_lock_tables(thd, table_list)) if (open_normal_and_derived_tables(thd, table_list))
{ {
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
...@@ -539,8 +539,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild) ...@@ -539,8 +539,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
DBUG_ENTER("mysqld_list_fields"); DBUG_ENTER("mysqld_list_fields");
DBUG_PRINT("enter",("table: %s",table_list->table_name)); DBUG_PRINT("enter",("table: %s",table_list->table_name));
table_list->lock_type= TL_UNLOCK; if (open_normal_and_derived_tables(thd, table_list))
if (open_and_lock_tables(thd, table_list))
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
table= table_list->table; table= table_list->table;
...@@ -1938,7 +1937,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -1938,7 +1937,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
bool res; bool res;
lex->all_selects_list= lsel; lex->all_selects_list= lsel;
res= open_and_lock_tables(thd, show_table_list); res= open_normal_and_derived_tables(thd, show_table_list);
if (schema_table->process_table(thd, show_table_list, if (schema_table->process_table(thd, show_table_list,
table, res, show_table_list->db, table, res, show_table_list->db,
show_table_list->alias)) show_table_list->alias))
...@@ -2043,7 +2042,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -2043,7 +2042,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
show_table_list->lock_type= lock_type; show_table_list->lock_type= lock_type;
lex->all_selects_list= &sel; lex->all_selects_list= &sel;
lex->derived_tables= 0; lex->derived_tables= 0;
res= open_and_lock_tables(thd, show_table_list); res= open_normal_and_derived_tables(thd, show_table_list);
if (schema_table->process_table(thd, show_table_list, table, if (schema_table->process_table(thd, show_table_list, table,
res, base_name, res, base_name,
show_table_list->alias)) show_table_list->alias))
......
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