Commit b528745d authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

When unifying arguments for comparion, binary strings won character strings,

and comparison was done binary. Now, a binary string wins a character sting 
taking in account their derivation. That means a character field wins a
binary literal and comparison is done according to the character field
collation, not binary. 
parent d31de697
...@@ -215,21 +215,21 @@ drop table t1; ...@@ -215,21 +215,21 @@ drop table t1;
create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word)); create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word));
insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae'); insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae');
update t1 set word2=word; 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 word t
1 1
select word, word=cast(0xdf AS CHAR) as t from t1 having t > 0; select word, word=cast(0xdf AS CHAR) as t from t1 having t > 0;
word t word t
ss 1 ss 1
1 1
select * from t1 where word=0xDF; select * from t1 where word=binary 0xDF;
word word2 word word2
select * from t1 where word=CAST(0xDF as CHAR); select * from t1 where word=CAST(0xDF as CHAR);
word word2 word word2
ss ss ss ss
select * from t1 where word2=0xDF; select * from t1 where word2=binary 0xDF;
word word2 word word2
select * from t1 where word2=CAST(0xDF as CHAR); 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); ...@@ -244,7 +244,7 @@ select * from t1 where word= 0xe4 or word=CAST(0xe4 as CHAR);
word word2 word word2
ae ae ae ae
select * from t1 where word between 0xDF and 0xDF; select * from t1 where word between binary 0xDF and binary 0xDF;
word word2 word word2
select * from t1 where word between CAST(0xDF AS CHAR) and CAST(0xDF AS CHAR); select * from t1 where word between CAST(0xDF AS CHAR) and CAST(0xDF AS CHAR);
...@@ -257,7 +257,7 @@ ae ae ...@@ -257,7 +257,7 @@ ae ae
select * from t1 where word like 'AE'; select * from t1 where word like 'AE';
word word2 word word2
ae ae ae ae
select * from t1 where word like 0xDF; select * from t1 where word like binary 0xDF;
word word2 word word2
select * from t1 where word like CAST(0xDF as CHAR); select * from t1 where word like CAST(0xDF as CHAR);
......
...@@ -52,21 +52,24 @@ drop table t1; ...@@ -52,21 +52,24 @@ drop table t1;
# Test bug report #152 (problem with index on latin1_de) # 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)); create table t1 (word varchar(255) not null, word2 varchar(255) not null, index(word));
insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae'); insert into t1 (word) values ('ss'),(0xDF),(0xE4),('ae');
update t1 set word2=word; 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 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 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 word2=CAST(0xDF as CHAR);
select * from t1 where word='ae'; select * from t1 where word='ae';
select * from t1 where word= 0xe4 or word=CAST(0xe4 as CHAR); 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 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 '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); select * from t1 where word like CAST(0xDF as CHAR);
drop table t1; drop table t1;
...@@ -39,7 +39,7 @@ Item::Item(): ...@@ -39,7 +39,7 @@ Item::Item():
{ {
marker= 0; marker= 0;
maybe_null=null_value=with_sum_func=unsigned_flag=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; name= 0;
decimals= 0; max_length= 0; decimals= 0; max_length= 0;
THD *thd= current_thd; THD *thd= current_thd;
...@@ -185,13 +185,6 @@ CHARSET_INFO * Item::default_charset() const ...@@ -185,13 +185,6 @@ CHARSET_INFO * Item::default_charset() const
bool DTCollation::aggregate(DTCollation &dt) 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)) if (!my_charset_same(collation, dt.collation))
{ {
/* /*
...@@ -199,13 +192,19 @@ bool DTCollation::aggregate(DTCollation &dt) ...@@ -199,13 +192,19 @@ bool DTCollation::aggregate(DTCollation &dt)
together with character strings. together with character strings.
Binaries have more precedance 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 else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment