Commit 2f96e073 authored by unknown's avatar unknown

merged


mysql-test/r/rpl_set_charset.result:
  Auto merged
mysql-test/r/select.result:
  Auto merged
mysql-test/t/rpl_set_charset.test:
  Auto merged
mysql-test/t/select.test:
  Auto merged
sql/slave.cc:
  Auto merged
parents 49d90b09 419ca715
......@@ -2602,32 +2602,31 @@ com_use(String *buffer __attribute__((unused)), char *line)
put_info("USE must be followed by a database name", INFO_ERROR);
return 0;
}
/*
We need to recheck the current database, because it may change
under our feet, for example if DROP DATABASE or RENAME DATABASE
(latter one not yet available by the time the comment was written)
/*
We need to recheck the current database, because it may change
under our feet, for example if DROP DATABASE or RENAME DATABASE
(latter one not yet available by the time the comment was written)
*/
current_db= 0; // Let's reset current_db, assume it's gone
/*
We don't care about in case of an error below because current_db
was just set to 0.
/* Let's reset current_db, assume it's gone */
my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
current_db= 0;
/*
We don't care about in case of an error below because current_db
was just set to 0.
*/
if (!mysql_query(&mysql, "SELECT DATABASE()") &&
(res= mysql_use_result(&mysql)))
{
row= mysql_fetch_row(res);
if (row[0] &&
(!current_db || cmp_database(charset_info, current_db, row[0])))
if (row[0])
{
my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
current_db= my_strdup(row[0], MYF(MY_WME));
}
(void) mysql_fetch_row(res); // Read eof
(void) mysql_fetch_row(res); // Read eof
mysql_free_result(res);
}
if (!current_db || cmp_database(charset_info, current_db, tmp))
if (!current_db || cmp_database(current_db,tmp))
{
if (one_database)
skip_updates= 1;
......
......@@ -45,5 +45,4 @@ C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF C0
D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF D0
E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF E0
F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF F0
drop table t1;
drop database mysqltest1;
......@@ -2348,3 +2348,19 @@ select * from t2,t3 where t2.s = t3.s;
s s
two two
drop table t1, t2, t3;
CREATE TABLE t1 (
i int(11) NOT NULL default '0',
c char(10) NOT NULL default '',
PRIMARY KEY (i),
UNIQUE KEY c (c)
) TYPE=MyISAM;
INSERT INTO t1 VALUES (1,'a');
INSERT INTO t1 VALUES (2,'b');
INSERT INTO t1 VALUES (3,'c');
EXPLAIN SELECT i FROM t1 WHERE i=1;
table type possible_keys key key_len ref rows Extra
t1 const PRIMARY PRIMARY 4 const 1 Using index
EXPLAIN SELECT i FROM t1 WHERE i=1;
table type possible_keys key key_len ref rows Extra
t1 const PRIMARY PRIMARY 4 const 1 Using index
DROP TABLE t1;
......@@ -27,9 +27,7 @@ use mysqltest1;
select "--- on slave ---";
select hex(a),b from t1 order by b;
connection master;
drop table t1;
drop database mysqltest1;
save_master_pos;
connection slave;
sync_with_master;
connection master;
drop database mysqltest1;
......@@ -1880,3 +1880,24 @@ select * from t3 where s = 'one';
select * from t1,t2 where t1.s = t2.s;
select * from t2,t3 where t2.s = t3.s;
drop table t1, t2, t3;
#
# Covering index is mentioned in EXPLAIN output for const tables (bug #5333)
#
CREATE TABLE t1 (
i int(11) NOT NULL default '0',
c char(10) NOT NULL default '',
PRIMARY KEY (i),
UNIQUE KEY c (c)
) TYPE=MyISAM;
INSERT INTO t1 VALUES (1,'a');
INSERT INTO t1 VALUES (2,'b');
INSERT INTO t1 VALUES (3,'c');
EXPLAIN SELECT i FROM t1 WHERE i=1;
EXPLAIN SELECT i FROM t1 WHERE i=1;
DROP TABLE t1;
......@@ -977,7 +977,7 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db)
int Query_log_event::exec_event(struct st_relay_log_info* rli)
{
int expected_error,actual_error= 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;
......@@ -995,6 +995,11 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
if (db_ok(thd->db, replicate_do_db, replicate_ignore_db))
{
thd->set_time((time_t)when);
/*
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));
......@@ -1082,7 +1087,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));
......@@ -1693,7 +1698,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
bool use_rli_only_for_errors)
{
char *load_data_query= 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);
thd->query_length= 0; // Should not be needed
thd->query_error= 0;
......@@ -1728,6 +1733,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
if (db_ok(thd->db, replicate_do_db, replicate_ignore_db))
{
thd->set_time((time_t)when);
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));
......@@ -1854,7 +1860,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)
......
......@@ -1290,6 +1290,7 @@ be equal for replication to work";
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
......@@ -1300,8 +1301,8 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
const char* table_name, bool overwrite)
{
ulong packet_len;
char *query;
char* save_db;
char *query, *save_db;
uint32 save_db_length;
Vio* save_vio;
HA_CHECK_OPT check_opt;
TABLE_LIST tables;
......@@ -1357,9 +1358,13 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, 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)
......@@ -3225,7 +3230,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)
{
......@@ -3391,7 +3396,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);
......
......@@ -852,6 +852,11 @@ err:
communication packet (in case of 'connect' or 'COM_INIT_DB')
we have to do end space removal in this function.
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).
RETURN VALUES
0 ok
1 error
......
......@@ -5930,6 +5930,7 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos)
{
table->key_read=1;
table->file->extra(HA_EXTRA_KEYREAD);
tab->index= tab->ref.key;
}
if ((error=join_read_const(tab)))
{
......
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