Commit 72d56253 authored by unknown's avatar unknown

Merge mysql.com:/space/bkroot/mysql-4.1

into mysql.com:/space/bk/b6391-mysql-4.1


sql/handler.cc:
  Auto merged
sql/item_func.cc:
  Auto merged
sql/sql_acl.cc:
  Auto merged
sql/sql_parse.cc:
  Auto merged
sql/sql_table.cc:
  Auto merged
parents 5fc09be9 220acb32
...@@ -11,8 +11,8 @@ get_lock("a",10) ...@@ -11,8 +11,8 @@ get_lock("a",10)
show binlog events; show binlog events;
Log_name Pos Event_type Server_id Orig_log_pos Info Log_name Pos Event_type Server_id Orig_log_pos Info
master-bin.000001 4 Start 1 4 Server ver: VERSION, Binlog ver: 3 master-bin.000001 4 Start 1 4 Server ver: VERSION, Binlog ver: 3
master-bin.000001 79 Query 1 79 use `test`; create database `drop-temp+table-test` master-bin.000001 79 Query 1 79 create database `drop-temp+table-test`
master-bin.000001 152 Query 1 152 use `drop-temp+table-test`; create temporary table `table:name` (a int) master-bin.000001 168 Query 1 168 use `drop-temp+table-test`; create temporary table `table:name` (a int)
master-bin.000001 246 Query 1 246 use `drop-temp+table-test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `drop-temp+table-test`.`table:name` master-bin.000001 262 Query 1 262 use `drop-temp+table-test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `drop-temp+table-test`.`table:name`
master-bin.000001 375 Query 1 375 use `drop-temp+table-test`; DO RELEASE_LOCK("a") master-bin.000001 391 Query 1 391 use `drop-temp+table-test`; DO RELEASE_LOCK("a")
drop database `drop-temp+table-test`; drop database `drop-temp+table-test`;
This diff is collapsed.
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
DROP DATABASE IF EXISTS mysqltest_prometheus;
DROP DATABASE IF EXISTS mysqltest_sisyfos;
DROP DATABASE IF EXISTS mysqltest_bob;
DROP DATABASE IF EXISTS mysqltest_bob;
CREATE DATABASE mysqltest_prometheus;
CREATE DATABASE mysqltest_sisyfos;
CREATE DATABASE mysqltest_bob;
USE mysqltest_sisyfos;
CREATE TABLE t1 (b int);
INSERT INTO t1 VALUES(1);
USE mysqltest_bob;
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES(2);
ALTER DATABASE mysqltest_sisyfos CHARACTER SET latin1;
USE mysqltest_sisyfos;
ALTER DATABASE mysqltest_bob CHARACTER SET latin1;
SHOW DATABASES;
Database
mysql
mysqltest_bob
mysqltest_prometheus
mysqltest_sisyfos
test
SHOW DATABASES;
Database
mysql
mysqltest_prometheus
mysqltest_sisyfos
test
DROP DATABASE IF EXISTS mysqltest_sisyfos;
USE mysqltest_prometheus;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
CREATE DATABASE mysqltest_sisyfos;
USE mysqltest_sisyfos;
CREATE TABLE t2 (a INT);
SHOW BINLOG EVENTS;
Log_name Pos Event_type Server_id Orig_log_pos Info
master-bin.000001 4 Start 1 4 Server ver: 4.1.8-debug-log, Binlog ver: 3
master-bin.000001 79 Query 1 79 DROP DATABASE IF EXISTS mysqltest_prometheus
master-bin.000001 174 Query 1 174 DROP DATABASE IF EXISTS mysqltest_sisyfos
master-bin.000001 263 Query 1 263 CREATE DATABASE mysqltest_prometheus
master-bin.000001 350 Query 1 350 CREATE DATABASE mysqltest_sisyfos
master-bin.000001 431 Query 1 431 use `mysqltest_sisyfos`; CREATE TABLE t1 (b int)
master-bin.000001 502 Query 1 502 use `mysqltest_sisyfos`; INSERT INTO t1 VALUES(1)
master-bin.000001 574 Query 1 574 ALTER DATABASE mysqltest_sisyfos CHARACTER SET latin1
master-bin.000001 675 Query 1 675 DROP DATABASE IF EXISTS mysqltest_sisyfos
master-bin.000001 764 Query 1 764 use `mysqltest_prometheus`; CREATE TABLE t1 (a INT)
master-bin.000001 838 Query 1 838 use `mysqltest_prometheus`; INSERT INTO t1 VALUES (1)
master-bin.000001 914 Query 1 914 CREATE DATABASE mysqltest_sisyfos
master-bin.000001 995 Query 1 995 use `mysqltest_sisyfos`; CREATE TABLE t2 (a INT)
SHOW DATABASES;
Database
mysql
mysqltest_bob
mysqltest_prometheus
mysqltest_sisyfos
test
SHOW DATABASES;
Database
mysql
mysqltest_prometheus
mysqltest_sisyfos
test
SHOW CREATE TABLE mysqltest_prometheus.t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE mysqltest_sisyfos.t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP DATABASE IF EXISTS mysqltest_prometheus;
DROP DATABASE IF EXISTS mysqltest_sisyfos;
DROP DATABASE IF EXISTS mysqltest_bob;
...@@ -12,4 +12,6 @@ use mysqltest; ...@@ -12,4 +12,6 @@ use mysqltest;
load data infile '../../std_data/rpl_loaddata.dat' into table test.t1; load data infile '../../std_data/rpl_loaddata.dat' into table test.t1;
show binlog events from 79; show binlog events from 79;
Log_name Pos Event_type Server_id Orig_log_pos Info Log_name Pos Event_type Server_id Orig_log_pos Info
master-bin.000001 79 Query 1 79 drop database if exists mysqltest
master-bin.000001 152 Query 1 152 create database mysqltest
drop database mysqltest; drop database mysqltest;
...@@ -154,9 +154,9 @@ select hex(c1), hex(c2) from t1; ...@@ -154,9 +154,9 @@ select hex(c1), hex(c2) from t1;
stop slave; stop slave;
delete from t1; delete from t1;
change master to master_log_pos=5801; change master to master_log_pos=5847;
start slave until master_log_file='master-bin.000001', master_log_pos=5937; start slave until master_log_file='master-bin.000001', master_log_pos=5983;
# Slave is supposed to stop _after_ the INSERT, even though 5937 is # Slave is supposed to stop _after_ the INSERT, even though 5983 is
# the position of the beginning of the INSERT; after SET slave is not # the position of the beginning of the INSERT; after SET slave is not
# supposed to increment position. # supposed to increment position.
wait_for_slave_to_stop; wait_for_slave_to_stop;
......
--binlog-do-db=mysqltest_sisyfos --binlog-do-db=mysqltest_prometheus
--replicate-do-db=mysqltest_sisyfos --replicate-do-db=mysqltest_prometheus
#
# Tests for replication of statements that manipulate databases.
#
# For this test file, we have a number of databases. All databases
# with "greek" names will be replicated on the slave, while other names
# (e.g., american) will not be replicated.
#
source include/master-slave.inc;
# Bug#6391 (binlog-do-db rules ignored)
# In this case, 'mysqltest_bob' should not be replicated to the slave.
--disable_warnings
DROP DATABASE IF EXISTS mysqltest_prometheus;
DROP DATABASE IF EXISTS mysqltest_sisyfos;
DROP DATABASE IF EXISTS mysqltest_bob;
sync_slave_with_master;
# This database is not replicated
DROP DATABASE IF EXISTS mysqltest_bob;
--enable_warnings
connection master;
CREATE DATABASE mysqltest_prometheus;
CREATE DATABASE mysqltest_sisyfos;
CREATE DATABASE mysqltest_bob;
USE mysqltest_sisyfos;
# These should be replicated
CREATE TABLE t1 (b int);
INSERT INTO t1 VALUES(1);
USE mysqltest_bob;
# These should *not* be replicated
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES(2);
# Current database is now 'mysqltest_bob'
# The following should be replicated
ALTER DATABASE mysqltest_sisyfos CHARACTER SET latin1;
USE mysqltest_sisyfos;
# The following should *not* be replicated
ALTER DATABASE mysqltest_bob CHARACTER SET latin1;
SHOW DATABASES;
sync_slave_with_master;
SHOW DATABASES;
connection master;
DROP DATABASE IF EXISTS mysqltest_sisyfos;
USE mysqltest_prometheus;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
CREATE DATABASE mysqltest_sisyfos;
USE mysqltest_sisyfos;
CREATE TABLE t2 (a INT);
SHOW BINLOG EVENTS;
SHOW DATABASES;
sync_slave_with_master;
SHOW DATABASES;
SHOW CREATE TABLE mysqltest_prometheus.t1;
SHOW CREATE TABLE mysqltest_sisyfos.t2;
connection master;
DROP DATABASE IF EXISTS mysqltest_prometheus;
DROP DATABASE IF EXISTS mysqltest_sisyfos;
DROP DATABASE IF EXISTS mysqltest_bob;
sync_slave_with_master;
...@@ -43,7 +43,7 @@ show slave status; ...@@ -43,7 +43,7 @@ show slave status;
# try replicate all until second insert to t2; # try replicate all until second insert to t2;
start slave until relay_log_file='slave-relay-bin.000002', relay_log_pos=537; start slave until relay_log_file='slave-relay-bin.000002', relay_log_pos=537;
sleep 2; sleep 4;
select * from t2; select * from t2;
--replace_result $MASTER_MYPORT MASTER_MYPORT --replace_result $MASTER_MYPORT MASTER_MYPORT
--replace_column 1 # 9 # 23 # 33 # --replace_column 1 # 9 # 23 # 33 #
......
...@@ -723,7 +723,7 @@ int ha_rollback_to_savepoint(THD *thd, char *savepoint_name) ...@@ -723,7 +723,7 @@ int ha_rollback_to_savepoint(THD *thd, char *savepoint_name)
if (unlikely((thd->options & OPTION_STATUS_NO_TRANS_UPDATE) && if (unlikely((thd->options & OPTION_STATUS_NO_TRANS_UPDATE) &&
my_b_tell(&thd->transaction.trans_log))) my_b_tell(&thd->transaction.trans_log)))
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE); Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE, FALSE);
if (mysql_bin_log.write(&qinfo)) if (mysql_bin_log.write(&qinfo))
error= 1; error= 1;
} }
...@@ -761,7 +761,7 @@ int ha_savepoint(THD *thd, char *savepoint_name) ...@@ -761,7 +761,7 @@ int ha_savepoint(THD *thd, char *savepoint_name)
innobase_savepoint(thd,savepoint_name, innobase_savepoint(thd,savepoint_name,
my_b_tell(&thd->transaction.trans_log)); my_b_tell(&thd->transaction.trans_log));
#endif #endif
Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE); Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE, FALSE);
if (mysql_bin_log.write(&qinfo)) if (mysql_bin_log.write(&qinfo))
error= 1; error= 1;
} }
......
...@@ -2010,7 +2010,7 @@ void item_user_lock_release(User_level_lock *ull) ...@@ -2010,7 +2010,7 @@ void item_user_lock_release(User_level_lock *ull)
tmp.copy(command, strlen(command), tmp.charset()); tmp.copy(command, strlen(command), tmp.charset());
tmp.append(ull->key,ull->key_length); tmp.append(ull->key,ull->key_length);
tmp.append("\")", 2); tmp.append("\")", 2);
Query_log_event qev(current_thd, tmp.ptr(), tmp.length(),1); Query_log_event qev(current_thd, tmp.ptr(), tmp.length(),1, FALSE);
qev.error_code=0; // this query is always safe to run on slave qev.error_code=0; // this query is always safe to run on slave
mysql_bin_log.write(&qev); mysql_bin_log.write(&qev);
} }
......
...@@ -1274,7 +1274,7 @@ bool MYSQL_LOG::write(Log_event* event_info) ...@@ -1274,7 +1274,7 @@ bool MYSQL_LOG::write(Log_event* event_info)
(local_db && !db_ok(local_db, binlog_do_db, binlog_ignore_db))) (local_db && !db_ok(local_db, binlog_do_db, binlog_ignore_db)))
{ {
VOID(pthread_mutex_unlock(&LOCK_log)); VOID(pthread_mutex_unlock(&LOCK_log));
DBUG_PRINT("error",("!db_ok")); DBUG_PRINT("error",("!db_ok('%s')", local_db));
DBUG_RETURN(0); DBUG_RETURN(0);
} }
#endif /* HAVE_REPLICATION */ #endif /* HAVE_REPLICATION */
...@@ -1317,7 +1317,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", ...@@ -1317,7 +1317,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
(uint) thd->variables.collation_connection->number, (uint) thd->variables.collation_connection->number,
(uint) thd->variables.collation_database->number, (uint) thd->variables.collation_database->number,
(uint) thd->variables.collation_server->number); (uint) thd->variables.collation_server->number);
Query_log_event e(thd, buf, written, 0); Query_log_event e(thd, buf, written, 0, FALSE);
e.set_log_pos(this); e.set_log_pos(this);
if (e.write(file)) if (e.write(file))
goto err; goto err;
...@@ -1333,7 +1333,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", ...@@ -1333,7 +1333,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
char *buf_end= strxmov(buf, "SET ONE_SHOT TIME_ZONE='", char *buf_end= strxmov(buf, "SET ONE_SHOT TIME_ZONE='",
thd->variables.time_zone->get_name()->ptr(), thd->variables.time_zone->get_name()->ptr(),
"'", NullS); "'", NullS);
Query_log_event e(thd, buf, buf_end - buf, 0); Query_log_event e(thd, buf, buf_end - buf, 0, FALSE);
e.set_log_pos(this); e.set_log_pos(this);
if (e.write(file)) if (e.write(file))
goto err; goto err;
...@@ -1402,7 +1402,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", ...@@ -1402,7 +1402,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
{ {
Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=0", 24, 0); Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=0", 24, 0, FALSE);
e.set_log_pos(this); e.set_log_pos(this);
if (e.write(file)) if (e.write(file))
goto err; goto err;
...@@ -1421,7 +1421,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", ...@@ -1421,7 +1421,7 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u",
{ {
if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS)
{ {
Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=1", 24, 0); Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=1", 24, 0, FALSE);
e.set_log_pos(this); e.set_log_pos(this);
if (e.write(file)) if (e.write(file))
goto err; goto err;
...@@ -1597,7 +1597,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) ...@@ -1597,7 +1597,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback)
we will add the "COMMIT mark and write the buffer to the binlog. we will add the "COMMIT mark and write the buffer to the binlog.
*/ */
{ {
Query_log_event qinfo(thd, "BEGIN", 5, TRUE); Query_log_event qinfo(thd, "BEGIN", 5, TRUE, FALSE);
/* /*
Imagine this is rollback due to net timeout, after all statements of Imagine this is rollback due to net timeout, after all statements of
the transaction succeeded. Then we want a zero-error code in BEGIN. the transaction succeeded. Then we want a zero-error code in BEGIN.
...@@ -1638,7 +1638,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) ...@@ -1638,7 +1638,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback)
Query_log_event qinfo(thd, Query_log_event qinfo(thd,
commit_or_rollback ? "COMMIT" : "ROLLBACK", commit_or_rollback ? "COMMIT" : "ROLLBACK",
commit_or_rollback ? 6 : 8, commit_or_rollback ? 6 : 8,
TRUE); TRUE, FALSE);
qinfo.error_code= 0; qinfo.error_code= 0;
qinfo.set_log_pos(this); qinfo.set_log_pos(this);
if (qinfo.write(&log_file) || flush_io_cache(&log_file) || if (qinfo.write(&log_file) || flush_io_cache(&log_file) ||
......
...@@ -780,7 +780,8 @@ void Query_log_event::pack_info(Protocol *protocol) ...@@ -780,7 +780,8 @@ void Query_log_event::pack_info(Protocol *protocol)
if (!(buf= my_malloc(9 + db_len + q_len, MYF(MY_WME)))) if (!(buf= my_malloc(9 + db_len + q_len, MYF(MY_WME))))
return; return;
pos= buf; pos= buf;
if (db && db_len) if (!(flags & LOG_EVENT_SUPPRESS_USE_F)
&& db && db_len)
{ {
pos= strmov(buf, "use `"); pos= strmov(buf, "use `");
memcpy(pos, db, db_len); memcpy(pos, db, db_len);
...@@ -872,9 +873,12 @@ int Query_log_event::write_data(IO_CACHE* file) ...@@ -872,9 +873,12 @@ int Query_log_event::write_data(IO_CACHE* file)
#ifndef MYSQL_CLIENT #ifndef MYSQL_CLIENT
Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
ulong query_length, bool using_trans) ulong query_length, bool using_trans,
:Log_event(thd_arg, !thd_arg->tmp_table_used ? bool suppress_use)
0 : LOG_EVENT_THREAD_SPECIFIC_F, using_trans), :Log_event(thd_arg,
((thd_arg->tmp_table_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0)
| (suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0)),
using_trans),
data_buf(0), query(query_arg), data_buf(0), query(query_arg),
db(thd_arg->db), q_len((uint32) query_length), db(thd_arg->db), q_len((uint32) query_length),
error_code(thd_arg->killed ? error_code(thd_arg->killed ?
...@@ -949,6 +953,8 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) ...@@ -949,6 +953,8 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db)
bool different_db= 1; bool different_db= 1;
if (!(flags & LOG_EVENT_SUPPRESS_USE_F))
{
if (db && last_db) if (db && last_db)
{ {
if (different_db= memcmp(last_db, db, db_len + 1)) if (different_db= memcmp(last_db, db, db_len + 1))
...@@ -956,7 +962,11 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) ...@@ -956,7 +962,11 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db)
} }
if (db && db[0] && different_db) if (db && db[0] && different_db)
{
fprintf(file, "use %s;\n", db); fprintf(file, "use %s;\n", db);
}
}
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10); end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
*end++=';'; *end++=';';
*end++='\n'; *end++='\n';
......
...@@ -264,6 +264,19 @@ struct sql_ex_info ...@@ -264,6 +264,19 @@ struct sql_ex_info
*/ */
#define LOG_EVENT_THREAD_SPECIFIC_F 0x4 #define LOG_EVENT_THREAD_SPECIFIC_F 0x4
/*
Suppress the generation of 'USE' statements before the actual
statement. This flag should be set for any events that does not need
the current database set to function correctly. Most notable cases
are 'CREATE DATABASE' and 'DROP DATABASE'.
This flags should only be used in exceptional circumstances, since
it introduce a significant change in behaviour regarding the
replication logic together with the flags --binlog-do-db and
--replicated-do-db.
*/
#define LOG_EVENT_SUPPRESS_USE_F 0x8
enum Log_event_type enum Log_event_type
{ {
UNKNOWN_EVENT= 0, START_EVENT= 1, QUERY_EVENT= 2, STOP_EVENT= 3, UNKNOWN_EVENT= 0, START_EVENT= 1, QUERY_EVENT= 2, STOP_EVENT= 3,
...@@ -331,8 +344,9 @@ class Log_event ...@@ -331,8 +344,9 @@ class Log_event
/* /*
Some 16 flags. Only one is really used now; look above for Some 16 flags. Only one is really used now; look above for
LOG_EVENT_TIME_F, LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F LOG_EVENT_TIME_F, LOG_EVENT_FORCED_ROTATE_F,
for notes. LOG_EVENT_THREAD_SPECIFIC_F, and LOG_EVENT_SUPPRESS_USE_F for
notes.
*/ */
uint16 flags; uint16 flags;
...@@ -465,7 +479,7 @@ class Query_log_event: public Log_event ...@@ -465,7 +479,7 @@ class Query_log_event: public Log_event
#ifndef MYSQL_CLIENT #ifndef MYSQL_CLIENT
Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length, Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
bool using_trans); bool using_trans, bool suppress_use);
const char* get_db() { return db; } const char* get_db() { return db; }
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol); void pack_info(Protocol* protocol);
......
...@@ -1230,7 +1230,7 @@ bool change_password(THD *thd, const char *host, const char *user, ...@@ -1230,7 +1230,7 @@ bool change_password(THD *thd, const char *host, const char *user,
new_password)); new_password));
thd->clear_error(); thd->clear_error();
mysql_update_log.write(thd, buff, query_length); mysql_update_log.write(thd, buff, query_length);
Query_log_event qinfo(thd, buff, query_length, 0); Query_log_event qinfo(thd, buff, query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -524,7 +524,7 @@ void close_temporary_tables(THD *thd) ...@@ -524,7 +524,7 @@ void close_temporary_tables(THD *thd)
{ {
/* The -1 is to remove last ',' */ /* The -1 is to remove last ',' */
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, query, (ulong)(end-query)-1, 0); Query_log_event qinfo(thd, query, (ulong)(end-query)-1, 0, FALSE);
/* /*
Imagine the thread had created a temp table, then was doing a SELECT, and Imagine the thread had created a temp table, then was doing a SELECT, and
the SELECT was killed. Then it's not clever to mark the statement above as the SELECT was killed. Then it's not clever to mark the statement above as
...@@ -1441,7 +1441,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db, ...@@ -1441,7 +1441,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
{ {
end = strxmov(strmov(query, "DELETE FROM `"), end = strxmov(strmov(query, "DELETE FROM `"),
db,"`.`",name,"`", NullS); db,"`.`",name,"`", NullS);
Query_log_event qinfo(thd, query, (ulong)(end-query), 0); Query_log_event qinfo(thd, query, (ulong)(end-query), 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
my_free(query, MYF(0)); my_free(query, MYF(0));
} }
......
...@@ -467,7 +467,29 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, ...@@ -467,7 +467,29 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
mysql_update_log.write(thd, query, query_length); mysql_update_log.write(thd, query, query_length);
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, query, query_length, 0); Query_log_event qinfo(thd, query, query_length, 0,
/* suppress_use */ TRUE);
/*
Write should use the database being created as the "current
database" and not the threads current database, which is the
default. If we do not change the "current database" to the
database being created, the CREATE statement will not be
replicated when using --binlog-do-db to select databases to be
replicated.
An example (--binlog-do-db=sisyfos):
CREATE DATABASE bob; # Not replicated
USE bob; # 'bob' is the current database
CREATE DATABASE sisyfos; # Not replicated since 'bob' is
# current database.
USE sisyfos; # Will give error on slave since
# database does not exist.
*/
qinfo.db = db;
qinfo.db_len = strlen(db);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
send_ok(thd, result); send_ok(thd, result);
...@@ -517,7 +539,15 @@ int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) ...@@ -517,7 +539,15 @@ int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
mysql_update_log.write(thd,thd->query, thd->query_length); mysql_update_log.write(thd,thd->query, thd->query_length);
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0,
/* suppress_use */ TRUE);
// Write should use the database being created as the "current
// database" and not the threads current database, which is the
// default.
qinfo.db = db;
qinfo.db_len = strlen(db);
thd->clear_error(); thd->clear_error();
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
...@@ -625,7 +655,15 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) ...@@ -625,7 +655,15 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
mysql_update_log.write(thd, query, query_length); mysql_update_log.write(thd, query, query_length);
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, query, query_length, 0); Query_log_event qinfo(thd, query, query_length, 0,
/* suppress_use */ TRUE);
// Write should use the database being created as the "current
// database" and not the threads current database, which is the
// default.
qinfo.db = db;
qinfo.db_len = strlen(db);
thd->clear_error(); thd->clear_error();
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
......
...@@ -216,7 +216,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, ...@@ -216,7 +216,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
if (error <= 0) if (error <= 0)
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
log_delayed); log_delayed, FALSE);
if (mysql_bin_log.write(&qinfo) && transactional_table) if (mysql_bin_log.write(&qinfo) && transactional_table)
error=1; error=1;
} }
...@@ -565,7 +565,7 @@ bool multi_delete::send_eof() ...@@ -565,7 +565,7 @@ bool multi_delete::send_eof()
if (error <= 0) if (error <= 0)
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
log_delayed); log_delayed, FALSE);
if (mysql_bin_log.write(&qinfo) && !normal_tables) if (mysql_bin_log.write(&qinfo) && !normal_tables)
local_error=1; // Log write failed: roll back the SQL statement local_error=1; // Log write failed: roll back the SQL statement
} }
...@@ -674,7 +674,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -674,7 +674,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
thd->tmp_table); thd->tmp_table, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
send_ok(thd); // This should return record count send_ok(thd); // This should return record count
......
...@@ -368,7 +368,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -368,7 +368,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
if (error <= 0) if (error <= 0)
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
log_delayed); log_delayed, FALSE);
if (mysql_bin_log.write(&qinfo) && transactional_table) if (mysql_bin_log.write(&qinfo) && transactional_table)
error=1; error=1;
} }
...@@ -1364,7 +1364,7 @@ bool delayed_insert::handle_inserts(void) ...@@ -1364,7 +1364,7 @@ bool delayed_insert::handle_inserts(void)
mysql_update_log.write(&thd,row->query, row->query_length); mysql_update_log.write(&thd,row->query, row->query_length);
if (row->log_query & DELAYED_LOG_BIN && using_bin_log) if (row->log_query & DELAYED_LOG_BIN && using_bin_log)
{ {
Query_log_event qinfo(&thd, row->query, row->query_length,0); Query_log_event qinfo(&thd, row->query, row->query_length,0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
...@@ -1539,7 +1539,7 @@ void select_insert::send_error(uint errcode,const char *err) ...@@ -1539,7 +1539,7 @@ void select_insert::send_error(uint errcode,const char *err)
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
table->file->has_transactions()); table->file->has_transactions(), FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
if (!table->tmp_table) if (!table->tmp_table)
...@@ -1581,7 +1581,7 @@ bool select_insert::send_eof() ...@@ -1581,7 +1581,7 @@ bool select_insert::send_eof()
if (!error) if (!error)
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
table->file->has_transactions()); table->file->has_transactions(), FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
if ((error2=ha_autocommit_or_rollback(thd,error)) && ! error) if ((error2=ha_autocommit_or_rollback(thd,error)) && ! error)
......
...@@ -2614,7 +2614,7 @@ mysql_execute_command(THD *thd) ...@@ -2614,7 +2614,7 @@ mysql_execute_command(THD *thd)
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); // No binlog error generated thd->clear_error(); // No binlog error generated
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
...@@ -2643,7 +2643,7 @@ mysql_execute_command(THD *thd) ...@@ -2643,7 +2643,7 @@ mysql_execute_command(THD *thd)
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); // No binlog error generated thd->clear_error(); // No binlog error generated
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
...@@ -2666,7 +2666,7 @@ mysql_execute_command(THD *thd) ...@@ -2666,7 +2666,7 @@ mysql_execute_command(THD *thd)
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); // No binlog error generated thd->clear_error(); // No binlog error generated
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
...@@ -3262,7 +3262,7 @@ purposes internal to the MySQL server", MYF(0)); ...@@ -3262,7 +3262,7 @@ purposes internal to the MySQL server", MYF(0));
mysql_update_log.write(thd, thd->query, thd->query_length); mysql_update_log.write(thd, thd->query, thd->query_length);
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
send_ok(thd); send_ok(thd);
...@@ -3278,7 +3278,7 @@ purposes internal to the MySQL server", MYF(0)); ...@@ -3278,7 +3278,7 @@ purposes internal to the MySQL server", MYF(0));
mysql_update_log.write(thd, thd->query, thd->query_length); mysql_update_log.write(thd, thd->query, thd->query_length);
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
send_ok(thd); send_ok(thd);
...@@ -3345,7 +3345,7 @@ purposes internal to the MySQL server", MYF(0)); ...@@ -3345,7 +3345,7 @@ purposes internal to the MySQL server", MYF(0));
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
...@@ -3366,7 +3366,7 @@ purposes internal to the MySQL server", MYF(0)); ...@@ -3366,7 +3366,7 @@ purposes internal to the MySQL server", MYF(0));
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
if (mqh_used && lex->sql_command == SQLCOM_GRANT) if (mqh_used && lex->sql_command == SQLCOM_GRANT)
...@@ -3409,7 +3409,7 @@ purposes internal to the MySQL server", MYF(0)); ...@@ -3409,7 +3409,7 @@ purposes internal to the MySQL server", MYF(0));
mysql_update_log.write(thd, thd->query, thd->query_length); mysql_update_log.write(thd, thd->query, thd->query_length);
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
......
...@@ -84,7 +84,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list) ...@@ -84,7 +84,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list)
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
send_ok(thd); send_ok(thd);
......
...@@ -282,7 +282,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -282,7 +282,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
if (!error) if (!error)
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
tmp_table_deleted && !some_tables_deleted); tmp_table_deleted && !some_tables_deleted,
FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
...@@ -1419,7 +1420,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -1419,7 +1420,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
test(create_info->options & test(create_info->options &
HA_LEX_CREATE_TMP_TABLE)); HA_LEX_CREATE_TMP_TABLE),
FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
} }
...@@ -2344,7 +2346,8 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table, ...@@ -2344,7 +2346,8 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table,
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
test(create_info->options & test(create_info->options &
HA_LEX_CREATE_TMP_TABLE)); HA_LEX_CREATE_TMP_TABLE),
FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
res= 0; res= 0;
...@@ -2455,7 +2458,7 @@ mysql_discard_or_import_tablespace(THD *thd, ...@@ -2455,7 +2458,7 @@ mysql_discard_or_import_tablespace(THD *thd,
mysql_update_log.write(thd, thd->query,thd->query_length); mysql_update_log.write(thd, thd->query,thd->query_length);
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
err: err:
...@@ -2842,7 +2845,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -2842,7 +2845,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
if (do_send_ok) if (do_send_ok)
...@@ -3237,7 +3240,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -3237,7 +3240,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
goto end_temporary; goto end_temporary;
...@@ -3372,7 +3375,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -3372,7 +3375,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, 0); Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
VOID(pthread_cond_broadcast(&COND_refresh)); VOID(pthread_cond_broadcast(&COND_refresh));
......
...@@ -344,7 +344,7 @@ int mysql_update(THD *thd, ...@@ -344,7 +344,7 @@ int mysql_update(THD *thd,
if (error <= 0) if (error <= 0)
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
log_delayed); log_delayed, FALSE);
if (mysql_bin_log.write(&qinfo) && transactional_table) if (mysql_bin_log.write(&qinfo) && transactional_table)
error=1; // Rollback update error=1; // Rollback update
} }
...@@ -1221,7 +1221,7 @@ bool multi_update::send_eof() ...@@ -1221,7 +1221,7 @@ bool multi_update::send_eof()
if (local_error <= 0) if (local_error <= 0)
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
log_delayed); log_delayed, FALSE);
if (mysql_bin_log.write(&qinfo) && trans_safe) if (mysql_bin_log.write(&qinfo) && trans_safe)
local_error= 1; // Rollback update local_error= 1; // Rollback update
} }
......
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