Commit 7a02bd9c authored by unknown's avatar unknown

Merge gbichot@bk-internal.mysql.com:/home/bk/mysql-4.0

into mysql.com:/home/mysql_src/mysql-4.0

parents bb88f4fb 32db5b4c
...@@ -1806,7 +1806,7 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) ...@@ -1806,7 +1806,7 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
{ {
int expected_error, actual_error= 0; int expected_error, actual_error= 0;
init_sql_alloc(&thd->mem_root, thd->variables.query_alloc_block_size,0); init_sql_alloc(&thd->mem_root, thd->variables.query_alloc_block_size,0);
thd->db= (char*) rewrite_db(db); thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed
/* /*
InnoDB internally stores the master log position it has processed so far; InnoDB internally stores the master log position it has processed so far;
...@@ -1836,6 +1836,11 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) ...@@ -1836,6 +1836,11 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
{ {
thd->set_time((time_t)when); thd->set_time((time_t)when);
thd->current_tablenr = 0; thd->current_tablenr = 0;
/*
We cannot use db_len from event to fill thd->db_length, because
rewrite_db() may have changed db.
*/
thd->db_length= thd->db ? strlen(thd->db) : 0;
thd->query_length= q_len; thd->query_length= q_len;
thd->query= (char *) query; thd->query= (char *) query;
VOID(pthread_mutex_lock(&LOCK_thread_count)); VOID(pthread_mutex_lock(&LOCK_thread_count));
...@@ -1930,7 +1935,7 @@ end: ...@@ -1930,7 +1935,7 @@ end:
VOID(pthread_mutex_lock(&LOCK_thread_count)); VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->db= 0; // prevent db from being freed thd->db= 0; // prevent db from being freed
thd->query= 0; // just to be sure thd->query= 0; // just to be sure
thd->query_length= 0; thd->query_length= thd->db_length =0;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
close_thread_tables(thd); close_thread_tables(thd);
free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC)); free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC));
...@@ -1968,7 +1973,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, ...@@ -1968,7 +1973,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
{ {
char *load_data_query= 0; char *load_data_query= 0;
init_sql_alloc(&thd->mem_root, thd->variables.query_alloc_block_size, 0); init_sql_alloc(&thd->mem_root, thd->variables.query_alloc_block_size, 0);
thd->db= (char*) rewrite_db(db); thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed
DBUG_ASSERT(thd->query == 0); DBUG_ASSERT(thd->query == 0);
clear_all_errors(thd, rli); clear_all_errors(thd, rli);
...@@ -2001,6 +2006,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, ...@@ -2001,6 +2006,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
{ {
thd->set_time((time_t)when); thd->set_time((time_t)when);
thd->current_tablenr = 0; thd->current_tablenr = 0;
thd->db_length= thd->db ? strlen(thd->db) : 0;
VOID(pthread_mutex_lock(&LOCK_thread_count)); VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_id = query_id++; thd->query_id = query_id++;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
...@@ -2117,7 +2123,7 @@ Slave: load data infile on table '%s' at log position %s in log \ ...@@ -2117,7 +2123,7 @@ Slave: load data infile on table '%s' at log position %s in log \
VOID(pthread_mutex_lock(&LOCK_thread_count)); VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->db= 0; thd->db= 0;
thd->query= 0; thd->query= 0;
thd->query_length= 0; thd->query_length= thd->db_length= 0;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
close_thread_tables(thd); close_thread_tables(thd);
if (load_data_query) if (load_data_query)
......
...@@ -1124,6 +1124,7 @@ slaves can't replicate a 5.0 or newer master."; ...@@ -1124,6 +1124,7 @@ slaves can't replicate a 5.0 or newer master.";
Used by fetch_master_table (used by LOAD TABLE tblname FROM MASTER and LOAD Used by fetch_master_table (used by LOAD TABLE tblname FROM MASTER and LOAD
DATA FROM MASTER). Drops the table (if 'overwrite' is true) and recreates it DATA FROM MASTER). Drops the table (if 'overwrite' is true) and recreates it
from the dump. Honours replication inclusion/exclusion rules. from the dump. Honours replication inclusion/exclusion rules.
db must be non-zero (guarded by assertion).
RETURN VALUES RETURN VALUES
0 success 0 success
...@@ -1134,8 +1135,8 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db, ...@@ -1134,8 +1135,8 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
const char* table_name, bool overwrite) const char* table_name, bool overwrite)
{ {
ulong packet_len = my_net_read(net); // read create table statement ulong packet_len = my_net_read(net); // read create table statement
char *query; char *query, *save_db;
char* save_db; uint32 save_db_length;
Vio* save_vio; Vio* save_vio;
HA_CHECK_OPT check_opt; HA_CHECK_OPT check_opt;
TABLE_LIST tables; TABLE_LIST tables;
...@@ -1193,9 +1194,13 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db, ...@@ -1193,9 +1194,13 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
thd->proc_info = "Creating table from master dump"; thd->proc_info = "Creating table from master dump";
// save old db in case we are creating in a different database // save old db in case we are creating in a different database
save_db = thd->db; save_db = thd->db;
save_db_length= thd->db_length;
thd->db = (char*)db; thd->db = (char*)db;
DBUG_ASSERT(thd->db);
thd->db_length= strlen(thd->db);
mysql_parse(thd, thd->query, packet_len); // run create table mysql_parse(thd, thd->query, packet_len); // run create table
thd->db = save_db; // leave things the way the were before thd->db = save_db; // leave things the way the were before
thd->db_length= save_db_length;
thd->options = save_options; thd->options = save_options;
if (thd->query_error) if (thd->query_error)
...@@ -2689,7 +2694,7 @@ err: ...@@ -2689,7 +2694,7 @@ err:
IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff)); IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
VOID(pthread_mutex_lock(&LOCK_thread_count)); VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query = thd->db = 0; // extra safety thd->query = thd->db = 0; // extra safety
thd->query_length = 0; thd->query_length= thd->db_length= 0;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
if (mysql) if (mysql)
{ {
...@@ -2838,7 +2843,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ ...@@ -2838,7 +2843,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \
err: err:
VOID(pthread_mutex_lock(&LOCK_thread_count)); VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query = thd->db = 0; // extra safety thd->query = thd->db = 0; // extra safety
thd->query_length = 0; thd->query_length= thd->db_length= 0;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
thd->proc_info = "Waiting for slave mutex on exit"; thd->proc_info = "Waiting for slave mutex on exit";
pthread_mutex_lock(&rli->run_lock); pthread_mutex_lock(&rli->run_lock);
......
...@@ -385,6 +385,15 @@ err: ...@@ -385,6 +385,15 @@ err:
} }
/*
Changes the current database.
NOTES
Do as little as possible in this function, as it is not called for the
replication slave SQL thread (for that thread, setting of thd->db is done
in ::exec_event() methods of log_event.cc).
*/
bool mysql_change_db(THD *thd,const char *name) bool mysql_change_db(THD *thd,const char *name)
{ {
int length, db_length; int length, db_length;
......
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