Commit bd868fb6 authored by unknown's avatar unknown

Merge bk-internal.mysql.com:/data0/bk/mysql-5.1-runtime

into  bk-internal.mysql.com:/data0/bk/mysql-5.1-wl3337


mysql-test/r/ps_1general.result:
  Auto merged
sql/sp_head.cc:
  Auto merged
sql/table.cc:
  Auto merged
sql/table.h:
  Auto merged
parents 37a25b53 9a770f53
...@@ -74,3 +74,16 @@ show tables; ...@@ -74,3 +74,16 @@ show tables;
Tables_in_test Tables_in_test
t1 t1
drop table t1; drop table t1;
drop database if exists mysqltest;
drop table if exists t1;
create table t1 (i int);
lock tables t1 read;
create database mysqltest;
drop table t1;
show open tables;
drop database mysqltest;
select 1;
1
1
unlock tables;
End of 5.0 tests
This diff is collapsed.
...@@ -308,17 +308,11 @@ prepare stmt4 from ' show engine bdb logs '; ...@@ -308,17 +308,11 @@ prepare stmt4 from ' show engine bdb logs ';
execute stmt4; execute stmt4;
prepare stmt4 from ' show grants for user '; prepare stmt4 from ' show grants for user ';
prepare stmt4 from ' show create table t2 '; prepare stmt4 from ' show create table t2 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show master status '; prepare stmt4 from ' show master status ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show master logs '; prepare stmt4 from ' show master logs ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show slave status '; prepare stmt4 from ' show slave status ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show warnings limit 20 '; prepare stmt4 from ' show warnings limit 20 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show errors limit 20 '; prepare stmt4 from ' show errors limit 20 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' show storage engines '; prepare stmt4 from ' show storage engines ';
execute stmt4; execute stmt4;
drop table if exists t5; drop table if exists t5;
...@@ -387,10 +381,8 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp ...@@ -387,10 +381,8 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
prepare stmt4 from ' use test ' ; prepare stmt4 from ' use test ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt3 from ' create database mysqltest '; prepare stmt3 from ' create database mysqltest ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
create database mysqltest ; create database mysqltest ;
prepare stmt3 from ' drop database mysqltest '; prepare stmt3 from ' drop database mysqltest ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
drop database mysqltest ; drop database mysqltest ;
prepare stmt3 from ' describe t2 '; prepare stmt3 from ' describe t2 ';
execute stmt3; execute stmt3;
...@@ -412,7 +404,6 @@ execute stmt1 ; ...@@ -412,7 +404,6 @@ execute stmt1 ;
prepare stmt1 from ' optimize table t1 ' ; prepare stmt1 from ' optimize table t1 ' ;
prepare stmt1 from ' analyze table t1 ' ; prepare stmt1 from ' analyze table t1 ' ;
prepare stmt1 from ' checksum table t1 ' ; prepare stmt1 from ' checksum table t1 ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' repair table t1 ' ; prepare stmt1 from ' repair table t1 ' ;
prepare stmt1 from ' restore table t1 from ''data.txt'' ' ; prepare stmt1 from ' restore table t1 from ''data.txt'' ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet ERROR HY000: This command is not supported in the prepared statement protocol yet
...@@ -440,11 +431,8 @@ execute stmt5; ...@@ -440,11 +431,8 @@ execute stmt5;
1 1
SET sql_mode=""; SET sql_mode="";
prepare stmt1 from ' flush local privileges ' ; prepare stmt1 from ' flush local privileges ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' reset query cache ' ; prepare stmt1 from ' reset query cache ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' KILL 0 '; prepare stmt1 from ' KILL 0 ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' explain select a from t1 order by b '; prepare stmt1 from ' explain select a from t1 order by b ';
execute stmt1; execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
......
...@@ -78,13 +78,10 @@ ERROR 42000: There is no such grant defined for user 'second_user' on host 'loca ...@@ -78,13 +78,10 @@ ERROR 42000: There is no such grant defined for user 'second_user' on host 'loca
drop database mysqltest; drop database mysqltest;
prepare stmt3 from ' grant all on test.t1 to drop_user@localhost prepare stmt3 from ' grant all on test.t1 to drop_user@localhost
identified by ''looser'' '; identified by ''looser'' ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
grant all on test.t1 to drop_user@localhost grant all on test.t1 to drop_user@localhost
identified by 'looser' ; identified by 'looser' ;
prepare stmt3 from ' revoke all privileges on test.t1 from prepare stmt3 from ' revoke all privileges on test.t1 from
drop_user@localhost '; drop_user@localhost ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
revoke all privileges on test.t1 from drop_user@localhost ; revoke all privileges on test.t1 from drop_user@localhost ;
prepare stmt3 from ' drop user drop_user@localhost '; prepare stmt3 from ' drop user drop_user@localhost ';
ERROR HY000: This command is not supported in the prepared statement protocol yet
drop user drop_user@localhost; drop user drop_user@localhost;
...@@ -284,11 +284,11 @@ call p1()| ...@@ -284,11 +284,11 @@ call p1()|
select * from t1| select * from t1|
id stmt_text status id stmt_text status
1 select 1 supported 1 select 1 supported
2 flush tables not supported 2 flush tables supported
3 handler t1 open as ha not supported 3 handler t1 open as ha not supported
4 analyze table t1 supported 4 analyze table t1 supported
5 check table t1 not supported 5 check table t1 not supported
6 checksum table t1 not supported 6 checksum table t1 supported
7 check table t1 not supported 7 check table t1 not supported
8 optimize table t1 supported 8 optimize table t1 supported
9 repair table t1 supported 9 repair table t1 supported
......
...@@ -81,3 +81,44 @@ show tables; ...@@ -81,3 +81,44 @@ show tables;
drop table t1; drop table t1;
# End of 4.1 tests # End of 4.1 tests
#
# Test for bug#21216 "Simultaneous DROP TABLE and SHOW OPEN TABLES causes
# server to crash". Crash (caused by failed assertion in 5.0 or by null
# pointer dereference in 5.1) happened when one ran SHOW OPEN TABLES
# while concurrently doing DROP TABLE (or RENAME TABLE, CREATE TABLE LIKE
# or any other command that takes name-lock) in other connection.
#
# Also includes test for similar bug#12212 "Crash that happens during
# removing of database name from cache" reappeared in 5.1 as bug#19403
# In its case crash happened when one concurrently executed DROP DATABASE
# and one of name-locking command.
#
--disable_warnings
drop database if exists mysqltest;
drop table if exists t1;
--enable_warnings
create table t1 (i int);
lock tables t1 read;
create database mysqltest;
connect (addconroot1, localhost, root,,);
--send drop table t1
connect (addconroot2, localhost, root,,);
# Server should not crash in any of the following statements
--disable_result_log
show open tables;
--enable_result_log
--send drop database mysqltest
connection default;
select 1;
unlock tables;
connection addconroot1;
--reap
connection addconroot2;
--reap
disconnect addconroot1;
disconnect addconroot2;
connection default;
--echo End of 5.0 tests
This diff is collapsed.
...@@ -330,17 +330,11 @@ prepare stmt4 from ' show engine bdb logs '; ...@@ -330,17 +330,11 @@ prepare stmt4 from ' show engine bdb logs ';
execute stmt4; execute stmt4;
--enable_result_log --enable_result_log
prepare stmt4 from ' show grants for user '; prepare stmt4 from ' show grants for user ';
--error 1295
prepare stmt4 from ' show create table t2 '; prepare stmt4 from ' show create table t2 ';
--error 1295
prepare stmt4 from ' show master status '; prepare stmt4 from ' show master status ';
--error 1295
prepare stmt4 from ' show master logs '; prepare stmt4 from ' show master logs ';
--error 1295
prepare stmt4 from ' show slave status '; prepare stmt4 from ' show slave status ';
--error 1295
prepare stmt4 from ' show warnings limit 20 '; prepare stmt4 from ' show warnings limit 20 ';
--error 1295
prepare stmt4 from ' show errors limit 20 '; prepare stmt4 from ' show errors limit 20 ';
prepare stmt4 from ' show storage engines '; prepare stmt4 from ' show storage engines ';
# The output depends upon the precise order in which # The output depends upon the precise order in which
...@@ -427,14 +421,12 @@ prepare stmt1 from ' execute stmt2 ' ; ...@@ -427,14 +421,12 @@ prepare stmt1 from ' execute stmt2 ' ;
prepare stmt1 from ' deallocate prepare never_prepared ' ; prepare stmt1 from ' deallocate prepare never_prepared ' ;
## switch the database connection ## switch the database connection
--error 1295 --error ER_UNSUPPORTED_PS
prepare stmt4 from ' use test ' ; prepare stmt4 from ' use test ' ;
## create/drop database ## create/drop database
--error 1295
prepare stmt3 from ' create database mysqltest '; prepare stmt3 from ' create database mysqltest ';
create database mysqltest ; create database mysqltest ;
--error 1295
prepare stmt3 from ' drop database mysqltest '; prepare stmt3 from ' drop database mysqltest ';
drop database mysqltest ; drop database mysqltest ;
...@@ -446,12 +438,12 @@ drop table t2 ; ...@@ -446,12 +438,12 @@ drop table t2 ;
--error 1146 --error 1146
execute stmt3; execute stmt3;
## lock/unlock ## lock/unlock
--error 1295 --error ER_UNSUPPORTED_PS
prepare stmt3 from ' lock tables t1 read ' ; prepare stmt3 from ' lock tables t1 read ' ;
--error 1295 --error ER_UNSUPPORTED_PS
prepare stmt3 from ' unlock tables ' ; prepare stmt3 from ' unlock tables ' ;
## Load/Unload table contents ## Load/Unload table contents
--error 1295 --error ER_UNSUPPORTED_PS
prepare stmt1 from ' load data infile ''data.txt'' prepare stmt1 from ' load data infile ''data.txt''
into table t1 fields terminated by ''\t'' '; into table t1 fields terminated by ''\t'' ';
prepare stmt1 from ' select * into outfile ''data.txt'' from t1 '; prepare stmt1 from ' select * into outfile ''data.txt'' from t1 ';
...@@ -459,13 +451,12 @@ execute stmt1 ; ...@@ -459,13 +451,12 @@ execute stmt1 ;
## ##
prepare stmt1 from ' optimize table t1 ' ; prepare stmt1 from ' optimize table t1 ' ;
prepare stmt1 from ' analyze table t1 ' ; prepare stmt1 from ' analyze table t1 ' ;
--error 1295
prepare stmt1 from ' checksum table t1 ' ; prepare stmt1 from ' checksum table t1 ' ;
prepare stmt1 from ' repair table t1 ' ; prepare stmt1 from ' repair table t1 ' ;
--error 1295 --error ER_UNSUPPORTED_PS
prepare stmt1 from ' restore table t1 from ''data.txt'' ' ; prepare stmt1 from ' restore table t1 from ''data.txt'' ' ;
## handler ## handler
--error 1295 --error ER_UNSUPPORTED_PS
prepare stmt1 from ' handler t1 open '; prepare stmt1 from ' handler t1 open ';
...@@ -491,11 +482,8 @@ SET sql_mode=ansi; ...@@ -491,11 +482,8 @@ SET sql_mode=ansi;
execute stmt5; execute stmt5;
SET sql_mode=""; SET sql_mode="";
--error 1295
prepare stmt1 from ' flush local privileges ' ; prepare stmt1 from ' flush local privileges ' ;
--error 1295
prepare stmt1 from ' reset query cache ' ; prepare stmt1 from ' reset query cache ' ;
--error 1295
prepare stmt1 from ' KILL 0 '; prepare stmt1 from ' KILL 0 ';
## simple explain ## simple explain
......
...@@ -117,15 +117,12 @@ drop database mysqltest; ...@@ -117,15 +117,12 @@ drop database mysqltest;
# #
# grant/revoke + drop user # grant/revoke + drop user
# #
--error 1295
prepare stmt3 from ' grant all on test.t1 to drop_user@localhost prepare stmt3 from ' grant all on test.t1 to drop_user@localhost
identified by ''looser'' '; identified by ''looser'' ';
grant all on test.t1 to drop_user@localhost grant all on test.t1 to drop_user@localhost
identified by 'looser' ; identified by 'looser' ;
--error 1295
prepare stmt3 from ' revoke all privileges on test.t1 from prepare stmt3 from ' revoke all privileges on test.t1 from
drop_user@localhost '; drop_user@localhost ';
revoke all privileges on test.t1 from drop_user@localhost ; revoke all privileges on test.t1 from drop_user@localhost ;
--error 1295
prepare stmt3 from ' drop user drop_user@localhost '; prepare stmt3 from ' drop user drop_user@localhost ';
drop user drop_user@localhost; drop user drop_user@localhost;
...@@ -874,6 +874,8 @@ end: ...@@ -874,6 +874,8 @@ end:
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use) int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use)
{ {
TABLE *table; TABLE *table;
TABLE_SHARE *share;
char *key_buff;
char key[MAX_DBKEY_LENGTH]; char key[MAX_DBKEY_LENGTH];
char *db= table_list->db; char *db= table_list->db;
uint key_length; uint key_length;
...@@ -903,17 +905,18 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use) ...@@ -903,17 +905,18 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use)
} }
/* /*
Create a table entry with the right key and with an old refresh version Create a table entry with the right key and with an old refresh version
Note that we must use my_malloc() here as this is freed by the table Note that we must use my_multi_malloc() here as this is freed by the
cache table cache
*/ */
if (!(table= (TABLE*) my_malloc(sizeof(*table)+ sizeof(TABLE_SHARE)+ if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
key_length, MYF(MY_WME | MY_ZEROFILL)))) &table, sizeof(*table),
&share, sizeof(*share),
&key_buff, key_length,
NULL))
DBUG_RETURN(-1); DBUG_RETURN(-1);
table->s= (TABLE_SHARE*) (table+1); table->s= share;
memcpy((table->s->table_cache_key.str= (char*) (table->s+1)), key, share->set_table_cache_key(key_buff, key, key_length);
key_length); share->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table
table->s->table_cache_key.length= key_length;
table->s->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table
table->in_use= thd; table->in_use= thd;
table->locked_by_name=1; table->locked_by_name=1;
table_list->table=table; table_list->table=table;
......
...@@ -161,17 +161,20 @@ sp_get_flags_for_command(LEX *lex) ...@@ -161,17 +161,20 @@ sp_get_flags_for_command(LEX *lex)
} }
/* fallthrough */ /* fallthrough */
case SQLCOM_ANALYZE: case SQLCOM_ANALYZE:
case SQLCOM_BACKUP_TABLE:
case SQLCOM_OPTIMIZE: case SQLCOM_OPTIMIZE:
case SQLCOM_PRELOAD_KEYS: case SQLCOM_PRELOAD_KEYS:
case SQLCOM_ASSIGN_TO_KEYCACHE: case SQLCOM_ASSIGN_TO_KEYCACHE:
case SQLCOM_CHECKSUM: case SQLCOM_CHECKSUM:
case SQLCOM_CHECK: case SQLCOM_CHECK:
case SQLCOM_HA_READ: case SQLCOM_HA_READ:
case SQLCOM_SHOW_AUTHORS:
case SQLCOM_SHOW_BINLOGS: case SQLCOM_SHOW_BINLOGS:
case SQLCOM_SHOW_BINLOG_EVENTS: case SQLCOM_SHOW_BINLOG_EVENTS:
case SQLCOM_SHOW_CHARSETS: case SQLCOM_SHOW_CHARSETS:
case SQLCOM_SHOW_COLLATIONS: case SQLCOM_SHOW_COLLATIONS:
case SQLCOM_SHOW_COLUMN_TYPES: case SQLCOM_SHOW_COLUMN_TYPES:
case SQLCOM_SHOW_CONTRIBUTORS:
case SQLCOM_SHOW_CREATE: case SQLCOM_SHOW_CREATE:
case SQLCOM_SHOW_CREATE_DB: case SQLCOM_SHOW_CREATE_DB:
case SQLCOM_SHOW_CREATE_FUNC: case SQLCOM_SHOW_CREATE_FUNC:
...@@ -180,16 +183,20 @@ sp_get_flags_for_command(LEX *lex) ...@@ -180,16 +183,20 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_SHOW_DATABASES: case SQLCOM_SHOW_DATABASES:
case SQLCOM_SHOW_ERRORS: case SQLCOM_SHOW_ERRORS:
case SQLCOM_SHOW_FIELDS: case SQLCOM_SHOW_FIELDS:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_GRANTS: case SQLCOM_SHOW_GRANTS:
case SQLCOM_SHOW_ENGINE_STATUS: case SQLCOM_SHOW_ENGINE_STATUS:
case SQLCOM_SHOW_ENGINE_LOGS: case SQLCOM_SHOW_ENGINE_LOGS:
case SQLCOM_SHOW_ENGINE_MUTEX: case SQLCOM_SHOW_ENGINE_MUTEX:
case SQLCOM_SHOW_EVENTS:
case SQLCOM_SHOW_KEYS: case SQLCOM_SHOW_KEYS:
case SQLCOM_SHOW_MASTER_STAT: case SQLCOM_SHOW_MASTER_STAT:
case SQLCOM_SHOW_NEW_MASTER: case SQLCOM_SHOW_NEW_MASTER:
case SQLCOM_SHOW_OPEN_TABLES: case SQLCOM_SHOW_OPEN_TABLES:
case SQLCOM_SHOW_PRIVILEGES: case SQLCOM_SHOW_PRIVILEGES:
case SQLCOM_SHOW_PROCESSLIST: case SQLCOM_SHOW_PROCESSLIST:
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_SCHEDULER_STATUS:
case SQLCOM_SHOW_SLAVE_HOSTS: case SQLCOM_SHOW_SLAVE_HOSTS:
case SQLCOM_SHOW_SLAVE_STAT: case SQLCOM_SHOW_SLAVE_STAT:
case SQLCOM_SHOW_STATUS: case SQLCOM_SHOW_STATUS:
...@@ -199,12 +206,7 @@ sp_get_flags_for_command(LEX *lex) ...@@ -199,12 +206,7 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_SHOW_TABLES: case SQLCOM_SHOW_TABLES:
case SQLCOM_SHOW_VARIABLES: case SQLCOM_SHOW_VARIABLES:
case SQLCOM_SHOW_WARNS: case SQLCOM_SHOW_WARNS:
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_AUTHORS:
case SQLCOM_SHOW_CONTRIBUTORS:
case SQLCOM_REPAIR: case SQLCOM_REPAIR:
case SQLCOM_BACKUP_TABLE:
case SQLCOM_RESTORE_TABLE: case SQLCOM_RESTORE_TABLE:
flags= sp_head::MULTI_RESULTS; flags= sp_head::MULTI_RESULTS;
break; break;
...@@ -262,6 +264,9 @@ sp_get_flags_for_command(LEX *lex) ...@@ -262,6 +264,9 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_CREATE_EVENT: case SQLCOM_CREATE_EVENT:
case SQLCOM_ALTER_EVENT: case SQLCOM_ALTER_EVENT:
case SQLCOM_DROP_EVENT: case SQLCOM_DROP_EVENT:
case SQLCOM_FLUSH:
case SQLCOM_INSTALL_PLUGIN:
case SQLCOM_UNINSTALL_PLUGIN:
flags= sp_head::HAS_COMMIT_OR_ROLLBACK; flags= sp_head::HAS_COMMIT_OR_ROLLBACK;
break; break;
default: default:
......
...@@ -634,6 +634,7 @@ TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name) ...@@ -634,6 +634,7 @@ TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name)
static void close_handle_and_leave_table_as_lock(TABLE *table) static void close_handle_and_leave_table_as_lock(TABLE *table)
{ {
TABLE_SHARE *share, *old_share= table->s; TABLE_SHARE *share, *old_share= table->s;
char *key_buff;
MEM_ROOT *mem_root= &table->mem_root; MEM_ROOT *mem_root= &table->mem_root;
DBUG_ENTER("close_handle_and_leave_table_as_lock"); DBUG_ENTER("close_handle_and_leave_table_as_lock");
...@@ -642,20 +643,14 @@ static void close_handle_and_leave_table_as_lock(TABLE *table) ...@@ -642,20 +643,14 @@ static void close_handle_and_leave_table_as_lock(TABLE *table)
This has to be done to ensure that the table share is removed from This has to be done to ensure that the table share is removed from
the table defintion cache as soon as the last instance is removed the table defintion cache as soon as the last instance is removed
*/ */
if ((share= (TABLE_SHARE*) alloc_root(mem_root, sizeof(*share)))) if (multi_alloc_root(mem_root,
&share, sizeof(*share),
&key_buff, old_share->table_cache_key.length,
NULL))
{ {
bzero((char*) share, sizeof(*share)); bzero((char*) share, sizeof(*share));
share->db.str= memdup_root(mem_root, old_share->db.str, share->set_table_cache_key(key_buff, old_share->table_cache_key.str,
old_share->db.length+1);
share->db.length= old_share->db.length;
share->table_name.str= memdup_root(mem_root,
old_share->table_name.str,
old_share->table_name.length+1);
share->table_name.length= old_share->table_name.length;
share->table_cache_key.str= memdup_root(mem_root,
old_share->table_cache_key.str,
old_share->table_cache_key.length); old_share->table_cache_key.length);
share->table_cache_key.length= old_share->table_cache_key.length;
share->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table() share->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table()
} }
...@@ -1603,28 +1598,18 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *db, ...@@ -1603,28 +1598,18 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *db,
const char *table_name) const char *table_name)
{ {
char *key; char *key;
uint key_length;
TABLE_SHARE *share= table->s; TABLE_SHARE *share= table->s;
TABLE_LIST table_list; TABLE_LIST table_list;
uint db_length, table_length;
DBUG_ENTER("rename_temporary_table"); DBUG_ENTER("rename_temporary_table");
if (!(key=(char*) alloc_root(&share->mem_root, if (!(key=(char*) alloc_root(&share->mem_root, MAX_DBKEY_LENGTH)))
(uint) (db_length= strlen(db))+
(uint) (table_length= strlen(table_name))+6+4)))
DBUG_RETURN(1); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */
table_list.db= (char*) db; table_list.db= (char*) db;
table_list.table_name= (char*) table_name; table_list.table_name= (char*) table_name;
share->db.str= share->table_cache_key.str= key; key_length= create_table_def_key(thd, key, &table_list, 1);
share->db.length= db_length; share->set_table_cache_key(key, key_length);
share->table_cache_key.length= create_table_def_key(thd, key,
&table_list, 1);
/*
Here we use the fact that table_name is stored as the second component
in the 'key' (after db_name), where components are separated with \0
*/
share->table_name.str= key+db_length+1;
share->table_name.length= table_length;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -1749,10 +1734,7 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) ...@@ -1749,10 +1734,7 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
{ {
TABLE *table= table_list->table; TABLE *table= table_list->table;
TABLE_SHARE *share; TABLE_SHARE *share;
char *db= table_list->db;
char *table_name= table_list->table_name; char *table_name= table_list->table_name;
char key[MAX_DBKEY_LENGTH];
uint key_length;
TABLE orig_table; TABLE orig_table;
DBUG_ENTER("reopen_name_locked_table"); DBUG_ENTER("reopen_name_locked_table");
...@@ -1762,7 +1744,6 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list) ...@@ -1762,7 +1744,6 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
orig_table= *table; orig_table= *table;
key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
if (open_unireg_entry(thd, table, table_list, table_name, if (open_unireg_entry(thd, table, table_list, table_name,
table->s->table_cache_key.str, table->s->table_cache_key.str,
......
...@@ -1740,6 +1740,20 @@ static bool check_prepared_statement(Prepared_statement *stmt, ...@@ -1740,6 +1740,20 @@ static bool check_prepared_statement(Prepared_statement *stmt,
case SQLCOM_SHOW_ENGINE_MUTEX: case SQLCOM_SHOW_ENGINE_MUTEX:
case SQLCOM_SHOW_CREATE_DB: case SQLCOM_SHOW_CREATE_DB:
case SQLCOM_SHOW_GRANTS: case SQLCOM_SHOW_GRANTS:
case SQLCOM_SHOW_BINLOG_EVENTS:
case SQLCOM_SHOW_MASTER_STAT:
case SQLCOM_SHOW_SLAVE_STAT:
case SQLCOM_SHOW_CREATE_PROC:
case SQLCOM_SHOW_CREATE_FUNC:
case SQLCOM_SHOW_CREATE_EVENT:
case SQLCOM_SHOW_CREATE:
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_FUNC_CODE:
case SQLCOM_SHOW_AUTHORS:
case SQLCOM_SHOW_CONTRIBUTORS:
case SQLCOM_SHOW_WARNS:
case SQLCOM_SHOW_ERRORS:
case SQLCOM_SHOW_BINLOGS:
case SQLCOM_DROP_TABLE: case SQLCOM_DROP_TABLE:
case SQLCOM_RENAME_TABLE: case SQLCOM_RENAME_TABLE:
case SQLCOM_ALTER_TABLE: case SQLCOM_ALTER_TABLE:
...@@ -1754,6 +1768,25 @@ static bool check_prepared_statement(Prepared_statement *stmt, ...@@ -1754,6 +1768,25 @@ static bool check_prepared_statement(Prepared_statement *stmt,
case SQLCOM_REPAIR: case SQLCOM_REPAIR:
case SQLCOM_ANALYZE: case SQLCOM_ANALYZE:
case SQLCOM_OPTIMIZE: case SQLCOM_OPTIMIZE:
case SQLCOM_CHANGE_MASTER:
case SQLCOM_RESET:
case SQLCOM_FLUSH:
case SQLCOM_SLAVE_START:
case SQLCOM_SLAVE_STOP:
case SQLCOM_INSTALL_PLUGIN:
case SQLCOM_UNINSTALL_PLUGIN:
case SQLCOM_CREATE_DB:
case SQLCOM_DROP_DB:
case SQLCOM_RENAME_DB:
case SQLCOM_CHECKSUM:
case SQLCOM_CREATE_USER:
case SQLCOM_RENAME_USER:
case SQLCOM_DROP_USER:
case SQLCOM_ASSIGN_TO_KEYCACHE:
case SQLCOM_PRELOAD_KEYS:
case SQLCOM_GRANT:
case SQLCOM_REVOKE:
case SQLCOM_KILL:
break; break;
default: default:
......
...@@ -8645,8 +8645,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -8645,8 +8645,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
share->primary_key= MAX_KEY; // Indicate no primary key share->primary_key= MAX_KEY; // Indicate no primary key
share->keys_for_keyread.init(); share->keys_for_keyread.init();
share->keys_in_use.init(); share->keys_in_use.init();
/* For easier error reporting */
share->table_cache_key= share->db;
/* Calculate which type of fields we will store in the temporary table */ /* Calculate which type of fields we will store in the temporary table */
......
...@@ -93,6 +93,7 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, ...@@ -93,6 +93,7 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
{ {
MEM_ROOT mem_root; MEM_ROOT mem_root;
TABLE_SHARE *share; TABLE_SHARE *share;
char *key_buff, *path_buff;
char path[FN_REFLEN]; char path[FN_REFLEN];
uint path_length; uint path_length;
DBUG_ENTER("alloc_table_share"); DBUG_ENTER("alloc_table_share");
...@@ -103,22 +104,17 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, ...@@ -103,22 +104,17 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
table_list->db, table_list->db,
table_list->table_name, "", 0); table_list->table_name, "", 0);
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0); init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
if ((share= (TABLE_SHARE*) alloc_root(&mem_root, if (multi_alloc_root(&mem_root,
sizeof(*share) + key_length + &share, sizeof(*share),
path_length +1))) &key_buff, key_length,
&path_buff, path_length + 1,
NULL))
{ {
bzero((char*) share, sizeof(*share)); bzero((char*) share, sizeof(*share));
share->table_cache_key.str= (char*) (share+1);
share->table_cache_key.length= key_length;
memcpy(share->table_cache_key.str, key, key_length);
/* Use the fact the key is db/0/table_name/0 */ share->set_table_cache_key(key_buff, key, key_length);
share->db.str= share->table_cache_key.str;
share->db.length= strlen(share->db.str);
share->table_name.str= share->db.str + share->db.length + 1;
share->table_name.length= strlen(share->table_name.str);
share->path.str= share->table_cache_key.str+ key_length; share->path.str= path_buff;
share->path.length= path_length; share->path.length= path_length;
strmov(share->path.str, path); strmov(share->path.str, path);
share->normalized_path.str= share->path.str; share->normalized_path.str= share->path.str;
......
...@@ -138,7 +138,16 @@ typedef struct st_table_share ...@@ -138,7 +138,16 @@ typedef struct st_table_share
CHARSET_INFO *table_charset; /* Default charset of string fields */ CHARSET_INFO *table_charset; /* Default charset of string fields */
MY_BITMAP all_set; MY_BITMAP all_set;
/* A pair "database_name\0table_name\0", widely used as simply a db name */ /*
Key which is used for looking-up table in table cache and in the list
of thread's temporary tables. Has the form of:
"database_name\0table_name\0" + optional part for temporary tables.
Note that all three 'table_cache_key', 'db' and 'table_name' members
must be set (and be non-zero) for tables in table cache. They also
should correspond to each other.
To ensure this one can use set_table_cache() methods.
*/
LEX_STRING table_cache_key; LEX_STRING table_cache_key;
LEX_STRING db; /* Pointer to db */ LEX_STRING db; /* Pointer to db */
LEX_STRING table_name; /* Table name (for open) */ LEX_STRING table_name; /* Table name (for open) */
...@@ -223,6 +232,60 @@ typedef struct st_table_share ...@@ -223,6 +232,60 @@ typedef struct st_table_share
uint part_state_len; uint part_state_len;
handlerton *default_part_db_type; handlerton *default_part_db_type;
#endif #endif
/*
Set share's table cache key and update its db and table name appropriately.
SYNOPSIS
set_table_cache_key()
key_buff Buffer with already built table cache key to be
referenced from share.
key_length Key length.
NOTES
Since 'key_buff' buffer will be referenced from share it should has same
life-time as share itself.
This method automatically ensures that TABLE_SHARE::table_name/db have
appropriate values by using table cache key as their source.
*/
void set_table_cache_key(char *key_buff, uint key_length)
{
table_cache_key.str= key_buff;
table_cache_key.length= key_length;
/*
Let us use the fact that the key is "db/0/table_name/0" + optional
part for temporary tables.
*/
db.str= table_cache_key.str;
db.length= strlen(db.str);
table_name.str= db.str + db.length + 1;
table_name.length= strlen(table_name.str);
}
/*
Set share's table cache key and update its db and table name appropriately.
SYNOPSIS
set_table_cache_key()
key_buff Buffer to be used as storage for table cache key
(should be at least key_length bytes).
key Value for table cache key.
key_length Key length.
NOTE
Since 'key_buff' buffer will be used as storage for table cache key
it should has same life-time as share itself.
*/
void set_table_cache_key(char *key_buff, const char *key, uint key_length)
{
memcpy(key_buff, key, key_length);
set_table_cache_key(key_buff, key_length);
}
} TABLE_SHARE; } TABLE_SHARE;
......
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