diff --git a/mysql-test/r/ctype_collate.result b/mysql-test/r/ctype_collate.result index f84613e086f..8ddc4e9a80a 100644 --- a/mysql-test/r/ctype_collate.result +++ b/mysql-test/r/ctype_collate.result @@ -719,3 +719,38 @@ DROP FUNCTION getText; DROP DATABASE test1; USE test; SET NAMES latin1; +# +# MDEV-11320, MySQL BUG#81810: Inconsistent sort order for blob/text between InnoDB and filesort +# +CREATE TABLE t1 ( +b LONGTEXT CHARACTER SET "latin1" COLLATE "latin1_bin", +KEY b (b(32)) +); +INSERT INTO t1 (b) VALUES ('a'), (_binary 0x1), (_binary 0x0), (''); +drop table t1; +CREATE TABLE t1 ( +b LONGTEXT CHARACTER SET "latin1" COLLATE "latin1_bin", +PRIMARY KEY b (b(32)) +); +INSERT INTO t1 (b) VALUES ('a'), (_binary 0x1), (_binary 0x0), (''); +explain +select hex(b) from t1 force index (PRIMARY) where b<'zzz'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 34 NULL 4 Using where +select hex(b) from t1 force index (PRIMARY) where b<'zzz'; +hex(b) +00 +01 + +61 +explain +select hex(b) from t1 where b<'zzz' order by b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where; Using filesort +select hex(b) from t1 where b<'zzz' order by b; +hex(b) +00 +01 + +61 +drop table t1; diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 898609e1ec2..c47a9b9fc06 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -1108,8 +1108,8 @@ length(c1) c1 0 SELECT DISTINCT length(c1), c1 FROM t1 ORDER BY c1; length(c1) c1 -0 2 A +0 2 B DROP TABLE t1; End of 4.1 tests diff --git a/mysql-test/t/ctype_collate.test b/mysql-test/t/ctype_collate.test index 23d34deb981..6704395a0a1 100644 --- a/mysql-test/t/ctype_collate.test +++ b/mysql-test/t/ctype_collate.test @@ -308,3 +308,34 @@ DROP FUNCTION getText; DROP DATABASE test1; USE test; SET NAMES latin1; + +--echo # +--echo # MDEV-11320, MySQL BUG#81810: Inconsistent sort order for blob/text between InnoDB and filesort +--echo # + +CREATE TABLE t1 ( + b LONGTEXT CHARACTER SET "latin1" COLLATE "latin1_bin", + KEY b (b(32)) +); +INSERT INTO t1 (b) VALUES ('a'), (_binary 0x1), (_binary 0x0), (''); + + +drop table t1; + +CREATE TABLE t1 ( + b LONGTEXT CHARACTER SET "latin1" COLLATE "latin1_bin", + PRIMARY KEY b (b(32)) +); + +INSERT INTO t1 (b) VALUES ('a'), (_binary 0x1), (_binary 0x0), (''); + +explain +select hex(b) from t1 force index (PRIMARY) where b<'zzz'; +select hex(b) from t1 force index (PRIMARY) where b<'zzz'; + +explain +select hex(b) from t1 where b<'zzz' order by b; +select hex(b) from t1 where b<'zzz' order by b; + +drop table t1; + diff --git a/sql/field.cc b/sql/field.cc index 846bb1fe674..da20f00a41f 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -8259,7 +8259,7 @@ void Field_blob::sort_string(uchar *to,uint length) uchar *blob; uint blob_length=get_length(); - if (!blob_length) + if (!blob_length && field_charset->pad_char == 0) bzero(to,length); else {