summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2004-09-07 21:30:28 +0200
committerunknown <serg@serg.mylan>2004-09-07 21:30:28 +0200
commit2f96e073d287fdf58f03eca3bf20f7467f757f81 (patch)
treee1cbd7bc7ac5fa0739864e430b898343bdfa631e
parent49d90b09f558b30adf1578dfcaf7d094e51609bd (diff)
parent419ca7152f30c6cbb8c8e8c4920a3d6e90e076a8 (diff)
downloadmariadb-git-2f96e073d287fdf58f03eca3bf20f7467f757f81.tar.gz
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
-rw-r--r--client/mysql.cc29
-rw-r--r--mysql-test/r/rpl_set_charset.result1
-rw-r--r--mysql-test/r/select.result16
-rw-r--r--mysql-test/t/rpl_set_charset.test4
-rw-r--r--mysql-test/t/select.test21
-rw-r--r--sql/log_event.cc14
-rw-r--r--sql/slave.cc13
-rw-r--r--sql/sql_db.cc5
-rw-r--r--sql/sql_select.cc1
9 files changed, 77 insertions, 27 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 0b43f9b80ec..36a2fecd661 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -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;
diff --git a/mysql-test/r/rpl_set_charset.result b/mysql-test/r/rpl_set_charset.result
index fd9c99d35d8..480d926fbba 100644
--- a/mysql-test/r/rpl_set_charset.result
+++ b/mysql-test/r/rpl_set_charset.result
@@ -45,5 +45,4 @@ C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF C0
D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF D0
E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF E0
F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF F0
-drop table t1;
drop database mysqltest1;
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index 8da1660a109..09bcfbb0e7f 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -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;
diff --git a/mysql-test/t/rpl_set_charset.test b/mysql-test/t/rpl_set_charset.test
index 1c0bd62fa55..269074b1c42 100644
--- a/mysql-test/t/rpl_set_charset.test
+++ b/mysql-test/t/rpl_set_charset.test
@@ -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;
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 57827f3cc7f..8228371142a 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -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;
diff --git a/sql/log_event.cc b/sql/log_event.cc
index ef77aa6603b..1f30e932c01 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -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)
diff --git a/sql/slave.cc b/sql/slave.cc
index 96b484a3965..a45c5c62322 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -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);
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index cfc75e3be95..426f7d36633 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -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
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f3eed672231..dbfecb9610f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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)))
{