summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <guilhem@mysql.com>2004-09-07 14:58:40 +0200
committerunknown <guilhem@mysql.com>2004-09-07 14:58:40 +0200
commit7a02bd9c3d8936b9d02bfe335b71c29c54db1742 (patch)
tree2b78b319ab7354380e377bdb4df20f95beb32711
parentbb88f4fbc3b1455c6bd92276a4016f6e91582227 (diff)
parent32db5b4c5eb4dddf6401f3a926645a1972fa5369 (diff)
downloadmariadb-git-7a02bd9c3d8936b9d02bfe335b71c29c54db1742.tar.gz
Merge gbichot@bk-internal.mysql.com:/home/bk/mysql-4.0
into mysql.com:/home/mysql_src/mysql-4.0
-rw-r--r--sql/log_event.cc14
-rw-r--r--sql/slave.cc13
-rw-r--r--sql/sql_db.cc9
3 files changed, 28 insertions, 8 deletions
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 5526795c9d1..f707eabebd5 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -1806,7 +1806,7 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
{
int expected_error, actual_error= 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;
@@ -1836,6 +1836,11 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
{
thd->set_time((time_t)when);
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= (char *) query;
VOID(pthread_mutex_lock(&LOCK_thread_count));
@@ -1930,7 +1935,7 @@ end:
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->db= 0; // prevent db from being freed
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));
close_thread_tables(thd);
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,
{
char *load_data_query= 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);
clear_all_errors(thd, 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->current_tablenr = 0;
+ thd->db_length= thd->db ? strlen(thd->db) : 0;
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_id = query_id++;
VOID(pthread_mutex_unlock(&LOCK_thread_count));
@@ -2117,7 +2123,7 @@ Slave: load data infile on table '%s' at log position %s in log \
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->db= 0;
thd->query= 0;
- thd->query_length= 0;
+ thd->query_length= thd->db_length= 0;
VOID(pthread_mutex_unlock(&LOCK_thread_count));
close_thread_tables(thd);
if (load_data_query)
diff --git a/sql/slave.cc b/sql/slave.cc
index 4416a2544ef..18e0ec5929f 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -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
DATA FROM MASTER). Drops the table (if 'overwrite' is true) and recreates it
from the dump. Honours replication inclusion/exclusion rules.
+ db must be non-zero (guarded by assertion).
RETURN VALUES
0 success
@@ -1134,8 +1135,8 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
const char* table_name, bool overwrite)
{
ulong packet_len = my_net_read(net); // read create table statement
- char *query;
- char* save_db;
+ char *query, *save_db;
+ uint32 save_db_length;
Vio* save_vio;
HA_CHECK_OPT check_opt;
TABLE_LIST tables;
@@ -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";
// save old db in case we are creating in a different database
save_db = thd->db;
+ save_db_length= thd->db_length;
thd->db = (char*)db;
+ DBUG_ASSERT(thd->db);
+ thd->db_length= strlen(thd->db);
mysql_parse(thd, thd->query, packet_len); // run create table
thd->db = save_db; // leave things the way the were before
+ thd->db_length= save_db_length;
thd->options = save_options;
if (thd->query_error)
@@ -2689,7 +2694,7 @@ err:
IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
VOID(pthread_mutex_lock(&LOCK_thread_count));
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));
if (mysql)
{
@@ -2838,7 +2843,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \
err:
VOID(pthread_mutex_lock(&LOCK_thread_count));
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));
thd->proc_info = "Waiting for slave mutex on exit";
pthread_mutex_lock(&rli->run_lock);
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 3d877403813..c8874701aa1 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -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)
{
int length, db_length;