List:Commits« Previous MessageNext Message »
From:Alexander Barkov Date:December 3 2009 9:23am
Subject:bzr push into mysql-5.1-bugteam branch (bar:3238 to 3239) Bug#44131
View as plain text  
 3239 Alexander Barkov	2009-12-03
      Bug#44131 Binary-mode "order by" returns records in incorrect order for UTF-8 strings
      
      Problem: Item_char_typecast reported wrong max_length when
      casting to BINARY, which lead, in particular, in wrong
      "ORDER BY BINARY(char_column)" results.
      
      Fix: making Item_char_typecast report correct max_length.
      
        @ mysql-test/r/ctype_utf16.result
          Fixing old incorrect test result.
        @ mysql-test/r/ctype_utf32.result
          Fixing old incorrect test result.
        @ mysql-test/r/ctype_utf8.result
          Adding new test
        @ mysql-test/t/ctype_utf8.test
          Adding new test
        @ sql/item_timefunc.cc
          Making Item_char_typecast report correct max_length
          when cast is done to BINARY.

    modified:
      mysql-test/r/ctype_utf8.result
      mysql-test/t/ctype_utf8.test
      sql/item_timefunc.cc
 3238 Evgeny Potemkin	2009-12-02 [merge]
      Auto-merged.

    modified:
      mysql-test/r/ps.result
      mysql-test/t/ps.test
      sql/item_cmpfunc.cc
      sql/sql_base.cc
      sql/sql_class.h
=== modified file 'mysql-test/r/ctype_utf8.result'
--- a/mysql-test/r/ctype_utf8.result	2008-11-21 13:32:45 +0000
+++ b/mysql-test/r/ctype_utf8.result	2009-12-03 09:22:34 +0000
@@ -1848,6 +1848,24 @@ select hex(_utf8 B'001111111111');
 ERROR HY000: Invalid utf8 character string: 'FF'
 select (_utf8 X'616263FF');
 ERROR HY000: Invalid utf8 character string: 'FF'
+#
+# Bug#44131 Binary-mode "order by" returns records in incorrect order for UTF-8 strings
+#
+CREATE TABLE t1 (id int not null primary key, name varchar(10)) character set utf8;
+INSERT INTO t1 VALUES
+(2,'一Y(name);
+id	name
+2	一二三01
+4	一二三02
+5	一二三08
+3	一二三09
+6	一二三11
+8	一二三21
+9	一二三81
+7	一二三91
+DROP TABLE t1;
 CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL);
 INSERT INTO t1 VALUES (70000, 1092), (70001, 1085), (70002, 1065);
 SELECT CONVERT(a, CHAR), CONVERT(b, CHAR) FROM t1 GROUP BY b;

=== modified file 'mysql-test/t/ctype_utf8.test'
--- a/mysql-test/t/ctype_utf8.test	2008-11-21 13:32:45 +0000
+++ b/mysql-test/t/ctype_utf8.test	2009-12-03 09:22:34 +0000
@@ -1440,6 +1440,16 @@ select hex(_utf8 B'001111111111');
 --error ER_INVALID_CHARACTER_STRING
 select (_utf8 X'616263FF');
 
+--echo #
+--echo # Bug#44131 Binary-mode "order by" returns records in incorrect order for UTF-8 strings
+--echo #
+CREATE TABLE t1 (id int not null primary key, name varchar(10)) character set utf8;
+INSERT INTO t1 VALUES
+(2,'一二三01'),(3,'一二三09'),(4,'一二三02'),(5,'一二三08'),
+(6,'一二三11'),(7,'一二三91'),(8,'一二三21'),(9,'一二三81');
+SELECT * FROM t1 ORDER BY BINARY(name);
+DROP TABLE t1;
+
 #
 # Bug #36772: When using UTF8, CONVERT with GROUP BY returns truncated results
 #

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	2009-11-19 22:49:13 +0000
+++ b/sql/item_timefunc.cc	2009-12-03 09:22:34 +0000
@@ -2554,9 +2554,9 @@ void Item_char_typecast::fix_length_and_
                        from_cs != &my_charset_bin &&
                        cast_cs != &my_charset_bin);
   collation.set(cast_cs, DERIVATION_IMPLICIT);
-  char_length= (cast_length >= 0) ?
-                 cast_length :
-                 args[0]->max_length / args[0]->collation.collation->mbmaxlen;
+  char_length= (cast_length >= 0) ? cast_length :
+                args[0]->max_length /
+                (cast_cs == &my_charset_bin ? 1 : args[0]->collation.collation->mbmaxlen);
   max_length= char_length * cast_cs->mbmaxlen;
 }
 

Attachment: [text/bzr-bundle] bzr/bar@mysql.com-20091203092234-dlnrwqzqy06yp4ft.bundle
Thread
bzr push into mysql-5.1-bugteam branch (bar:3238 to 3239) Bug#44131Alexander Barkov3 Dec