diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index ddb5355f9ec252d1d083d92fb165d623b34fdcc6..aacd80f19bb08dc2b4eeb529b2a300c48790b211 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -169,3 +169,28 @@ hex(s1) drop table t1; create table t1 (a text character set utf8, primary key(a(360))); ERROR 42000: Specified key was too long; max key length is 1000 bytes +CREATE TABLE t1 ( a varchar(10) ) CHARACTER SET utf8; +INSERT INTO t1 VALUES ( 'test' ); +SELECT a.a, b.a FROM t1 a, t1 b WHERE a.a = b.a; +a a +test test +SELECT a.a, b.a FROM t1 a, t1 b WHERE a.a = 'test' and b.a = 'test'; +a a +test test +SELECT a.a, b.a FROM t1 a, t1 b WHERE a.a = b.a and a.a = 'test'; +a a +test test +DROP TABLE t1; +create table t1 (a char(255) character set utf8); +insert into t1 values('b'),('b'); +select * from t1 where a = 'b'; +a +b +b +select * from t1 where a = 'b' and a = 'b'; +a +b +b +select * from t1 where a = 'b' and a != 'b'; +a +drop table t1; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 797af89c6ad7f056c11c6500a2dec5e179dfe504..08a84df3ff752993cadfa3b530995f1c6d365809 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -105,3 +105,22 @@ drop table t1; # --error 1071 create table t1 (a text character set utf8, primary key(a(360))); + + +# +# Bug 2959 +# UTF8 charset breaks joins with mixed column/string constant +# +CREATE TABLE t1 ( a varchar(10) ) CHARACTER SET utf8; +INSERT INTO t1 VALUES ( 'test' ); +SELECT a.a, b.a FROM t1 a, t1 b WHERE a.a = b.a; +SELECT a.a, b.a FROM t1 a, t1 b WHERE a.a = 'test' and b.a = 'test'; +SELECT a.a, b.a FROM t1 a, t1 b WHERE a.a = b.a and a.a = 'test'; +DROP TABLE t1; + +create table t1 (a char(255) character set utf8); +insert into t1 values('b'),('b'); +select * from t1 where a = 'b'; +select * from t1 where a = 'b' and a = 'b'; +select * from t1 where a = 'b' and a != 'b'; +drop table t1; diff --git a/sql/item.h b/sql/item.h index 59c030f3db57a1eaa2afbae87b175a2462bb1f4b..727132916f0675472fa6d45befa820eb24174201 100644 --- a/sql/item.h +++ b/sql/item.h @@ -533,7 +533,8 @@ class Item_string :public Item bool eq(const Item *item, bool binary_cmp) const; Item *new_item() { - return new Item_string(name, str_value.ptr(), max_length, &my_charset_bin); + return new Item_string(name, str_value.ptr(), + str_value.length(), &my_charset_bin); } String *const_string() { return &str_value; } inline void append(char *str, uint length) { str_value.append(str, length); }