Commit 226d978a authored by aelkin@mysql.com's avatar aelkin@mysql.com

BUG#14157: utf8 encoding in binlog without set character_set_client e.g DROP temporary

Binlog lacks encoding info about DROPped temporary table.

Idea of the fix is to switch temporary to system_charset_info when a temporary table
is DROPped for binlog. Since that is the server, that automatically, but not the client, who generates the query
the binlog should be updated on the server's encoding for the coming DROP.
The `write_binlog_with_system_charset()' is introduced to replace similar problematic places in the code.
parent 17a80c9d
......@@ -17,6 +17,7 @@ master-bin.000001 # Query 1 # create database `drop-temp+table-test`
master-bin.000001 # Query 1 # use `drop-temp+table-test`; create temporary table shortn1 (a int)
master-bin.000001 # Query 1 # use `drop-temp+table-test`; create temporary table `table:name` (a int)
master-bin.000001 # Query 1 # use `drop-temp+table-test`; create temporary table shortn2 (a int)
master-bin.000001 # Query 1 # use `drop-temp+table-test`; SET ONE_SHOT CHARACTER_SET_CLIENT=33,COLLATION_CONNECTION=8,COLLATION_DATABASE=8,COLLATION_SERVER=8
master-bin.000001 # Query 1 # use `drop-temp+table-test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `drop-temp+table-test`.`shortn2`,`drop-temp+table-test`.`table:name`,`drop-temp+table-test`.`shortn1`
master-bin.000001 # Query 1 # use `drop-temp+table-test`; DO RELEASE_LOCK("a")
drop database `drop-temp+table-test`;
......@@ -249,7 +249,8 @@ master-bin.000001 1056 Query 1 1056 use `test`; insert t0 select * from t1
master-bin.000001 1117 Query 1 1117 use `test`; DO RELEASE_LOCK("a")
master-bin.000001 1172 Query 1 1172 use `test`; insert into t0 select GET_LOCK("lock1",null)
master-bin.000001 1251 Query 1 1251 use `test`; create table t2 (n int) engine=innodb
master-bin.000001 1323 Query 1 1323 use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `test`.`t1`,`test`.`ti`
master-bin.000001 1424 Query 1 1424 use `test`; DO RELEASE_LOCK("lock1")
master-bin.000001 1323 Query 1 1323 use `test`; SET ONE_SHOT CHARACTER_SET_CLIENT=33,COLLATION_CONNECTION=8,COLLATION_DATABASE=8,COLLATION_SERVER=8
master-bin.000001 1457 Query 1 1457 use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `test`.`t1`,`test`.`ti`
master-bin.000001 1558 Query 1 1558 use `test`; DO RELEASE_LOCK("lock1")
do release_lock("lock1");
drop table t0,t2;
......@@ -101,4 +101,9 @@ HEX(f)
select HEX(f) from t4;
HEX(f)
835C
drop table t1, t2, t03, t04, t3, t4;
flush logs;
select * from t5 /* must be (1),(1) */;
a
1
1
drop table t1, t2, t03, t04, t3, t4, t5;
......@@ -103,3 +103,7 @@ select * from t1 /* must be 1 */;
f
1
drop table t1;
select * from t1;
a
1
drop table t1;
......@@ -114,8 +114,17 @@ select HEX(f) from t3;
select HEX(f) from t04;
select HEX(f) from t4;
#
#14157: utf8 encoding in binlog without set character_set_client
#
flush logs;
--exec $MYSQL --default-character-set=koi8r test -e 'create table if not exists t5 (a int); set names koi8r; create temporary table ` ` (a int); insert into ` ` values (1); insert into t5 select * from ` `'
# resulted log is client charset insensitive (latin1 not koi8r) as it must be
--exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000006 | $MYSQL --default-character-set=latin1
select * from t5 /* must be (1),(1) */;
# clean up
drop table t1, t2, t03, t04, t3, t4;
drop table t1, t2, t03, t04, t3, t4, t5;
# End of 4.1 tests
......@@ -156,4 +156,16 @@ select * from t1 /* must be 1 */;
connection master;
drop table t1;
#
#14157: utf8 encoding in binlog without set character_set_client
#
--exec $MYSQL --default-character-set=koi8r test -e 'create table t1 (a int); set names koi8r; create temporary table `ÔÏÌØËÏ ÇÅÒÏÉ ÓÒÅÚÁÀÔ ÒÁÛÐÉÌÅÍ ÇÒÉÍ` (a int); insert into `ÔÏÌØËÏ ÇÅÒÏÉ ÓÒÅÚÁÀÔ ÒÁÛÐÉÌÅÍ ÇÒÉÍ` values (1); insert into t1 select * from `ÔÏÌØËÏ ÇÅÒÏÉ ÓÒÅÚÁÀÔ ÒÁÛÐÉÌÅÍ ÇÒÉÍ`'
sync_slave_with_master;
#connection slave;
select * from t1;
connection master;
drop table t1;
# End of 4.1 tests
......@@ -1275,6 +1275,13 @@ inline int hexchar_to_int(char c)
return -1;
}
inline void write_binlog_with_system_charset(THD * thd, Query_log_event * qinfo)
{
CHARSET_INFO * cs_save= thd->variables.character_set_client;
thd->variables.character_set_client= system_charset_info;
mysql_bin_log.write(qinfo);
thd->variables.character_set_client= cs_save;
}
/*
Some functions that are different in the embedded library and the normal
......
......@@ -615,7 +615,7 @@ void close_temporary_tables(THD *thd)
rightfully causing the slave to stop.
*/
qinfo.error_code= 0;
mysql_bin_log.write(&qinfo);
write_binlog_with_system_charset(thd, &qinfo);
}
else
{
......
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