List:Commits« Previous MessageNext Message »
From:Li-Bing.Song Date:August 12 2009 3:54am
Subject:bzr commit into mysql-5.0-bugteam branch (Li-Bing.Song:2787) Bug#45516
View as plain text  
#At file:///home/anders/work/bzrwork/bug45516/mysql-5.0-bugteam/ based on revid:davi.arnaut@stripped-33youze713fou6g6

 2787 Li-Bing.Song@stripped	2009-08-12
      BUG#45516 SQL thread does not use database charset properly
              
      Replication SQL thread does not set database default charset to 
      thd->variables.collation_database properly, when executing LOAD DATA binlog.
      This bug can be repeated by using "LOAD DATA" command in STATEMENT mode.
              
      This patch adds code to find the default character set of the current database 
      then assign it to thd->db_charset when slave server begins to execute a relay log.
      The test of this bug is added into rpl_loaddata_charset.test 

    added:
      mysql-test/include/rpl_loaddata_charset.inc
      mysql-test/std_data/loaddata_utf8.dat
    modified:
      mysql-test/r/rpl_loaddata_charset.result
      mysql-test/t/rpl_loaddata_charset.test
      sql/log_event.cc
=== added file 'mysql-test/include/rpl_loaddata_charset.inc'
--- a/mysql-test/include/rpl_loaddata_charset.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/rpl_loaddata_charset.inc	2009-08-12 03:54:05 +0000
@@ -0,0 +1,35 @@
+connection master;
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest;
+--enable_warnings
+
+CREATE DATABASE mysqltest CHARSET UTF8;
+USE mysqltest;
+CREATE TABLE t (cl varchar(100)) CHARSET UTF8;
+
+if (!$LOAD_LOCAL)
+{
+  LOAD DATA INFILE '../std_data_ln/loaddata_utf8.dat' INTO TABLE t
+  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
+}
+if ($LOAD_LOCAL)
+{
+  LOAD DATA LOCAL INFILE './std_data/loaddata_utf8.dat' INTO TABLE t
+  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
+}
+
+save_master_pos;
+echo ----------content on master----------;
+SELECT hex(cl) FROM t;
+
+connection slave;
+sync_with_master;
+echo ----------content on slave----------;
+USE mysqltest;
+SELECT hex(cl) FROM t;
+
+connection master;
+DROP DATABASE mysqltest;
+save_master_pos;
+connection slave;
+sync_with_master;

=== modified file 'mysql-test/r/rpl_loaddata_charset.result'
--- a/mysql-test/r/rpl_loaddata_charset.result	2007-03-01 07:52:25 +0000
+++ b/mysql-test/r/rpl_loaddata_charset.result	2009-08-12 03:54:05 +0000
@@ -35,3 +35,44 @@ C3BF
 D0AA
 D0AA
 drop table t1;
+-------------test bug#45516------------------
+DROP DATABASE IF EXISTS mysqltest;
+CREATE DATABASE mysqltest CHARSET UTF8;
+USE mysqltest;
+CREATE TABLE t (cl varchar(100)) CHARSET UTF8;
+LOAD DATA LOCAL INFILE './std_data/loaddata_utf8.dat' INTO TABLE t
+FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
+----------content on master----------
+SELECT hex(cl) FROM t;
+hex(cl)
+E4B880E4BA8CE4B889
+E59B9BE4BA94E585AD
+E4B883E585ABE4B99D
+----------content on slave----------
+USE mysqltest;
+SELECT hex(cl) FROM t;
+hex(cl)
+E4B880E4BA8CE4B889
+E59B9BE4BA94E585AD
+E4B883E585ABE4B99D
+DROP DATABASE mysqltest;
+DROP DATABASE IF EXISTS mysqltest;
+CREATE DATABASE mysqltest CHARSET UTF8;
+USE mysqltest;
+CREATE TABLE t (cl varchar(100)) CHARSET UTF8;
+LOAD DATA INFILE '../std_data_ln/loaddata_utf8.dat' INTO TABLE t
+FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
+----------content on master----------
+SELECT hex(cl) FROM t;
+hex(cl)
+E4B880E4BA8CE4B889
+E59B9BE4BA94E585AD
+E4B883E585ABE4B99D
+----------content on slave----------
+USE mysqltest;
+SELECT hex(cl) FROM t;
+hex(cl)
+E4B880E4BA8CE4B889
+E59B9BE4BA94E585AD
+E4B883E585ABE4B99D
+DROP DATABASE mysqltest;

=== added file 'mysql-test/std_data/loaddata_utf8.dat'
--- a/mysql-test/std_data/loaddata_utf8.dat	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/loaddata_utf8.dat	2009-08-12 03:54:05 +0000
@@ -0,0 +1,3 @@
+一二三
+四五六
+七八九

=== modified file 'mysql-test/t/rpl_loaddata_charset.test'
--- a/mysql-test/t/rpl_loaddata_charset.test	2007-03-01 07:52:25 +0000
+++ b/mysql-test/t/rpl_loaddata_charset.test	2009-08-12 03:54:05 +0000
@@ -31,3 +31,20 @@ select hex(a) from t1;
 connection master;
 drop table t1;
 sync_slave_with_master;
+
+#
+# Bug#45516 
+#   When slave SQL thread executing LOAD DATA command, the
+#   thd->variables.collation_database was not set properly to the default
+#   database charset
+#
+
+echo -------------test bug#45516------------------;
+
+# LOAD DATA INFILE
+let $LOAD_LOCAL=1;
+source include/rpl_loaddata_charset.inc;
+
+# LOAD DATA LOCAL INFILE
+let $LOAD_LOCAL=0;
+source include/rpl_loaddata_charset.inc;

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-07-24 15:58:58 +0000
+++ b/sql/log_event.cc	2009-08-12 03:54:05 +0000
@@ -1918,6 +1918,8 @@ int Query_log_event::exec_event(struct s
 {
   const char *new_db= rewrite_db(db);
   int expected_error,actual_error= 0;
+  HA_CREATE_INFO db_options;
+
   /*
     Colleagues: please never free(thd->catalog) in MySQL. This would lead to
     bugs as here thd->catalog is a part of an alloced block, not an entire
@@ -1926,6 +1928,14 @@ int Query_log_event::exec_event(struct s
   */
   thd->catalog= catalog_len ? (char *) catalog : (char *)"";
   thd->set_db(new_db, (uint) strlen(new_db));          /* allocates a copy of 'db' */
+
+  /*
+    Setting the character set and collation of the current database thd->db.
+   */
+  load_db_opt_by_name(thd, thd->db, &db_options);
+  if (db_options.default_table_charset)
+    thd->db_charset= db_options.default_table_charset;
+
   thd->variables.auto_increment_increment= auto_increment_increment;
   thd->variables.auto_increment_offset=    auto_increment_offset;
 

Attachment: [text/bzr-bundle] bzr/li-bing.song@sun.com-20090812035405-67bgvvno3x9tlfnx.bundle
Thread
bzr commit into mysql-5.0-bugteam branch (Li-Bing.Song:2787) Bug#45516Li-Bing.Song20 Aug