diff -urN mysql-5.5.8/client/client_priv.h mysql-5.5.8_patch/client/client_priv.h --- mysql-5.5.8/client/client_priv.h 2010-12-04 04:58:26.000000000 +1100 +++ mysql-5.5.8_patch/client/client_priv.h 2011-01-16 15:44:25.000000000 +1100 @@ -85,7 +85,7 @@ OPT_WRITE_BINLOG, OPT_DUMP_DATE, OPT_INIT_COMMAND, OPT_PLUGIN_DIR, - OPT_DEFAULT_PLUGIN, + OPT_DEFAULT_PLUGIN, OPT_THREAD_ID, OPT_MAX_CLIENT_OPTION }; diff -urN mysql-5.5.8/client/mysqlbinlog.cc mysql-5.5.8_patch/client/mysqlbinlog.cc --- mysql-5.5.8/client/mysqlbinlog.cc 2010-12-04 04:58:26.000000000 +1100 +++ mysql-5.5.8_patch/client/mysqlbinlog.cc 2011-01-16 15:44:26.000000000 +1100 @@ -44,6 +44,8 @@ char server_version[SERVER_VERSION_LENGTH]; ulong server_id = 0; +ulong thread_id = 0; +ulong current_thread_id = 0; // needed by net_serv.c ulong bytes_sent = 0L, bytes_received = 0L; @@ -716,6 +718,17 @@ if (server_id && (server_id != ev->server_id)) /* skip just this event, continue processing the log. */ goto end; + if (thread_id) { + if (ev_type == QUERY_EVENT) + { + current_thread_id = ((Query_log_event*)ev)->thread_id; + } + if (current_thread_id && (thread_id != current_thread_id)) + { + /* skip just this event, continue processing the log. */ + goto end; + } + } if (((my_time_t)(ev->when) >= stop_datetime) || (pos >= stop_position_mot)) { @@ -1084,6 +1097,10 @@ "Extract only binlog entries created by the server having the given id.", &server_id, &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"thread-id", OPT_THREAD_ID, + "Extract only binlog entries created by the thread having the given id.", + &thread_id, &thread_id, 0, GET_ULONG, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"set-charset", OPT_SET_CHARSET, "Add 'SET NAMES character_set' to the output.", &charset, &charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, diff -urN mysql-5.5.8/mysql-test/r/mysqlbinlog_threadid.result mysql-5.5.8_patch/mysql-test/r/mysqlbinlog_threadid.result --- mysql-5.5.8/mysql-test/r/mysqlbinlog_threadid.result 1970-01-01 10:00:00.000000000 +1000 +++ mysql-5.5.8_patch/mysql-test/r/mysqlbinlog_threadid.result 2011-01-16 15:44:19.000000000 +1100 @@ -0,0 +1,174 @@ +SET GLOBAL server_id := 1; +SET SESSION pseudo_thread_id := 111; +reset master; +set timestamp=1000000000; +drop table if exists t1,t2,t3,t4,t5,t03,t04; +create table t1 (id int auto_increment not null primary key); +insert into t1 values (); +SET GLOBAL server_id := 2; +insert into t1 values (); +SET SESSION pseudo_thread_id := 222; +insert into t1 values (); +SET GLOBAL server_id := 1; +insert into t1 values (); +flush logs; + +--- No filtering -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +DELIMITER /*!*/; +ROLLBACK/*!*/; +use test/*!*/; +SET TIMESTAMP=1000000000/*!*/; +SET @@session.pseudo_thread_id=999999999/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; +SET @@session.sql_mode=0/*!*/; +SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; +/*!\C latin1 *//*!*/; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/; +SET @@session.lc_time_names=0/*!*/; +SET @@session.collation_database=DEFAULT/*!*/; +DROP TABLE IF EXISTS `t1`,`t2`,`t3`,`t4`,`t5`,`t03`,`t04` /* generated by server */ +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +create table t1 (id int auto_increment not null primary key) +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=1/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=2/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=3/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=4/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- thread-id=111 -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +DELIMITER /*!*/; +ROLLBACK/*!*/; +use test/*!*/; +SET TIMESTAMP=1000000000/*!*/; +SET @@session.pseudo_thread_id=999999999/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; +SET @@session.sql_mode=0/*!*/; +SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; +/*!\C latin1 *//*!*/; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/; +SET @@session.lc_time_names=0/*!*/; +SET @@session.collation_database=DEFAULT/*!*/; +DROP TABLE IF EXISTS `t1`,`t2`,`t3`,`t4`,`t5`,`t03`,`t04` /* generated by server */ +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +create table t1 (id int auto_increment not null primary key) +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=1/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=2/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- thread-id=222 -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +DELIMITER /*!*/; +ROLLBACK/*!*/; +SET TIMESTAMP=1000000000/*!*/; +SET @@session.pseudo_thread_id=999999999/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; +SET @@session.sql_mode=0/*!*/; +SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; +/*!\C latin1 *//*!*/; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/; +SET @@session.lc_time_names=0/*!*/; +SET @@session.collation_database=DEFAULT/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=3/*!*/; +use test/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +BEGIN +/*!*/; +SET INSERT_ID=4/*!*/; +SET TIMESTAMP=1000000000/*!*/; +insert into t1 values () +/*!*/; +SET TIMESTAMP=1000000000/*!*/; +COMMIT +/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; + +--- thread-id=999 -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +DELIMITER /*!*/; +ROLLBACK/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +drop table if exists t1,t2,t3,t4,t5,t03,t04; diff -urN mysql-5.5.8/mysql-test/t/mysqlbinlog_threadid.test mysql-5.5.8_patch/mysql-test/t/mysqlbinlog_threadid.test --- mysql-5.5.8/mysql-test/t/mysqlbinlog_threadid.test 1970-01-01 10:00:00.000000000 +1000 +++ mysql-5.5.8_patch/mysql-test/t/mysqlbinlog_threadid.test 2011-01-16 15:44:13.000000000 +1100 @@ -0,0 +1,70 @@ +-- source include/have_binlog_format_statement.inc + +-- source include/have_log_bin.inc + +# Set the server id, so we are sure what the output will be +SET GLOBAL server_id := 1; +SET SESSION pseudo_thread_id := 111; + +# Deletes all the binary logs +reset master; + +# we need this for getting fixed timestamps inside of this test +set timestamp=1000000000; + +--disable_warnings +drop table if exists t1,t2,t3,t4,t5,t03,t04; +--enable_warnings + +create table t1 (id int auto_increment not null primary key); + +# simple test for simple statement and various events +insert into t1 values (); + +SET GLOBAL server_id := 2; +insert into t1 values (); + +SET SESSION pseudo_thread_id := 222; +insert into t1 values (); + +SET GLOBAL server_id := 1; +insert into t1 values (); + +flush logs; + +# +# We should use --short-form everywhere because in other case output will +# be time dependend. Better than nothing. +# +let $MYSQLD_DATADIR= `select @@datadir`; + +# Test no filtering +# delimiters are for easier debugging in future +--disable_query_log +select "--- No filtering --" as ""; +--enable_query_log +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --base64-output=decode-rows $MYSQLD_DATADIR/master-bin.000001 + +# Test --thread-id=... +--disable_query_log +select "--- thread-id=111 --" as ""; +--enable_query_log +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --base64-output=decode-rows --thread-id=111 $MYSQLD_DATADIR/master-bin.000001 + +--disable_query_log +select "--- thread-id=222 --" as ""; +--enable_query_log +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --base64-output=decode-rows --thread-id=222 $MYSQLD_DATADIR/master-bin.000001 + +--disable_query_log +select "--- thread-id=999 --" as ""; +--enable_query_log +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--exec $MYSQL_BINLOG --short-form --base64-output=decode-rows --thread-id=999 $MYSQLD_DATADIR/master-bin.000001 + +--disable_warnings +drop table if exists t1,t2,t3,t4,t5,t03,t04; +--enable_warnings