From: Date: June 29 2007 8:26pm Subject: bk commit into 5.0 tree (gshchepa:1.2508) BUG#29205 List-Archive: http://lists.mysql.com/commits/29979 X-Bug: 29205 Message-Id: <20070629182647.9160A3D40F9@localhost.localdomain> Below is the list of changes that have just been committed into a local 5.0 repository of uchum. When uchum does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-06-29 23:26:40+05:00, gshchepa@stripped +3 -0 Fixed bug #29205. When the UNION statement forced conversion of an UTF8 charset value to a binary charset value, a byte length of the resulting value was truncated to the CHAR_LENGTH of the original UTF8 value. mysql-test/r/ctype_utf8.result@stripped, 2007-06-29 23:05:33+05:00, gshchepa@stripped +8 -0 Updated test case for bug #29205. mysql-test/t/ctype_utf8.test@stripped, 2007-06-29 23:04:54+05:00, gshchepa@stripped +8 -0 Updated test case for bug #29205. sql/item.cc@stripped, 2007-06-29 23:04:41+05:00, gshchepa@stripped +13 -4 Fixed bug #29205. The calculation of data length was modified in the Item_type_holder::join_types method to take into account possible conversion of a multibyte charset value to a binary charset value, where each multibyte character have to be converted into a sequence of bytes (not to a single byte of binary charset). diff -Nrup a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result --- a/mysql-test/r/ctype_utf8.result 2007-04-13 10:05:52 +05:00 +++ b/mysql-test/r/ctype_utf8.result 2007-06-29 23:05:33 +05:00 @@ -1657,3 +1657,11 @@ colA colB colA colB 1 foo 1 foo 2 foo bar 2 foo bar DROP TABLE t1, t2; +select "н1234567890" union select _binary "1"; +н1234567890 +н1234567890 +1 +select 1 union select "н1234567890"; +1 +1 +н1234567890 diff -Nrup a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test --- a/mysql-test/t/ctype_utf8.test 2007-04-13 10:05:52 +05:00 +++ b/mysql-test/t/ctype_utf8.test 2007-06-29 23:04:54 +05:00 @@ -1338,3 +1338,11 @@ INSERT INTO t2 (colA, colB) VALUES (1, ' SELECT * FROM t1 JOIN t2 ON t1.colA=t2.colA AND t1.colB=t2.colB WHERE t1.colA < 3; DROP TABLE t1, t2; + +# +# Bug#29205: truncation of UTF8 values when the UNION statement +# forces collation to the binary charset +# + +select "н1234567890" union select _binary "1"; +select 1 union select "н1234567890"; diff -Nrup a/sql/item.cc b/sql/item.cc --- a/sql/item.cc 2007-06-22 03:25:20 +05:00 +++ b/sql/item.cc 2007-06-29 23:04:41 +05:00 @@ -6578,9 +6578,13 @@ bool Item_type_holder::join_types(THD *t case STRING_RESULT: { const char *old_cs, *old_derivation; - uint32 old_max_chars= max_length / collation.collation->mbmaxlen; + CHARSET_INFO *old_collation= collation.collation; + uint32 old_max_length, item_max_length; old_cs= collation.collation->name; old_derivation= collation.derivation_name(); + old_max_length= max_length; + item_max_length= display_length(item); + if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV)) { my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), @@ -6595,9 +6599,14 @@ bool Item_type_holder::join_types(THD *t expansion of the size of the values because of character set conversions. */ - max_length= max(old_max_chars * collation.collation->mbmaxlen, - display_length(item) / item->collation.collation->mbmaxlen * - collation.collation->mbmaxlen); + if (collation.collation != &my_charset_bin) + { + old_max_length= old_max_length / old_collation->mbmaxlen * + collation.collation->mbmaxlen; + item_max_length= item_max_length / item->collation.collation->mbmaxlen * + collation.collation->mbmaxlen; + } + max_length= max(old_max_length, item_max_length); break; } case REAL_RESULT: