diff --git a/mysql-test/r/ctype_latin1_de.result b/mysql-test/r/ctype_latin1_de.result index 630fef9b679..e0cb7008899 100644 --- a/mysql-test/r/ctype_latin1_de.result +++ b/mysql-test/r/ctype_latin1_de.result @@ -215,21 +215,21 @@ drop table t1; create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word)); insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae'); update t1 set word2=word; -select word, word=0xdf as t from t1 having t > 0; +select word, word=binary 0xdf as t from t1 having t > 0; word t ß 1 select word, word=cast(0xdf AS CHAR) as t from t1 having t > 0; word t ss 1 ß 1 -select * from t1 where word=0xDF; +select * from t1 where word=binary 0xDF; word word2 ß ß select * from t1 where word=CAST(0xDF as CHAR); word word2 ss ss ß ß -select * from t1 where word2=0xDF; +select * from t1 where word2=binary 0xDF; word word2 ß ß select * from t1 where word2=CAST(0xDF as CHAR); @@ -244,7 +244,7 @@ select * from t1 where word= 0xe4 or word=CAST(0xe4 as CHAR); word word2 ä ä ae ae -select * from t1 where word between 0xDF and 0xDF; +select * from t1 where word between binary 0xDF and binary 0xDF; word word2 ß ß select * from t1 where word between CAST(0xDF AS CHAR) and CAST(0xDF AS CHAR); @@ -257,7 +257,7 @@ ae ae select * from t1 where word like 'AE'; word word2 ae ae -select * from t1 where word like 0xDF; +select * from t1 where word like binary 0xDF; word word2 ß ß select * from t1 where word like CAST(0xDF as CHAR); diff --git a/mysql-test/t/ctype_latin1_de.test b/mysql-test/t/ctype_latin1_de.test index b63af87601b..22a4e14158d 100644 --- a/mysql-test/t/ctype_latin1_de.test +++ b/mysql-test/t/ctype_latin1_de.test @@ -52,21 +52,24 @@ drop table t1; # Test bug report #152 (problem with index on latin1_de) # +# +# The below checks both binary and character comparisons. +# create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word)); insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae'); update t1 set word2=word; -select word, word=0xdf as t from t1 having t > 0; +select word, word=binary 0xdf as t from t1 having t > 0; select word, word=cast(0xdf AS CHAR) as t from t1 having t > 0; -select * from t1 where word=0xDF; +select * from t1 where word=binary 0xDF; select * from t1 where word=CAST(0xDF as CHAR); -select * from t1 where word2=0xDF; +select * from t1 where word2=binary 0xDF; select * from t1 where word2=CAST(0xDF as CHAR); select * from t1 where word='ae'; select * from t1 where word= 0xe4 or word=CAST(0xe4 as CHAR); -select * from t1 where word between 0xDF and 0xDF; +select * from t1 where word between binary 0xDF and binary 0xDF; select * from t1 where word between CAST(0xDF AS CHAR) and CAST(0xDF AS CHAR); select * from t1 where word like 'ae'; select * from t1 where word like 'AE'; -select * from t1 where word like 0xDF; +select * from t1 where word like binary 0xDF; select * from t1 where word like CAST(0xDF as CHAR); drop table t1; diff --git a/sql/item.cc b/sql/item.cc index 950f27c5d69..fea68837014 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -39,7 +39,7 @@ Item::Item(): { marker= 0; maybe_null=null_value=with_sum_func=unsigned_flag=0; - set_charset(&my_charset_bin, DERIVATION_COERCIBLE); + set_charset(default_charset(), DERIVATION_COERCIBLE); name= 0; decimals= 0; max_length= 0; THD *thd= current_thd; @@ -185,13 +185,6 @@ CHARSET_INFO * Item::default_charset() const bool DTCollation::aggregate(DTCollation &dt) { - if (collation == &my_charset_bin || dt.collation == &my_charset_bin) - { - collation= &my_charset_bin; - derivation= derivation > dt.derivation ? derivation : dt.derivation; - return 0; - } - if (!my_charset_same(collation, dt.collation)) { /* @@ -199,13 +192,19 @@ bool DTCollation::aggregate(DTCollation &dt) together with character strings. Binaries have more precedance */ - if ((derivation <= dt.derivation) && (collation == &my_charset_bin)) + if (collation == &my_charset_bin) { - // Do nothing + if (derivation <= dt.derivation) + ; // Do nothing + else + set(dt); } - else if ((dt.derivation <= derivation) && (dt.collation==&my_charset_bin)) + else if (dt.collation == &my_charset_bin) { - set(dt); + if (dt.derivation <= derivation) + set(dt); + else + ; // Do nothing } else {