summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgluh@gluh.mysql.r18.ru <>2004-08-23 19:13:47 +0400
committergluh@gluh.mysql.r18.ru <>2004-08-23 19:13:47 +0400
commit23535cce16a69b83b6527dc38828920d12324c0a (patch)
tree7d7dc55cf5529bceb2600e7277d2ace46c286aee
parentd5bf903e4d05260a596c512efba2412c0807a30b (diff)
downloadmariadb-git-23535cce16a69b83b6527dc38828920d12324c0a.tar.gz
Fix for bug #5134: WHERE x = 'bar' AND x LIKE BINARY 'bar' returns
wrong results
-rw-r--r--mysql-test/r/binary.result18
-rw-r--r--mysql-test/t/binary.test13
-rw-r--r--sql/sql_select.cc10
3 files changed, 39 insertions, 2 deletions
diff --git a/mysql-test/r/binary.result b/mysql-test/r/binary.result
index 2de8b01bc3a..054918e8df3 100644
--- a/mysql-test/r/binary.result
+++ b/mysql-test/r/binary.result
@@ -80,3 +80,21 @@ NULL
select b from t1 having binary b like '';
b
drop table t1;
+create table t1( firstname char(20), lastname char(20));
+insert into t1 values ("john","doe"),("John","Doe");
+select * from t1 where firstname='john' and firstname like binary 'john';
+firstname lastname
+john doe
+select * from t1 where firstname='john' and binary 'john' = firstname;
+firstname lastname
+john doe
+select * from t1 where firstname='john' and firstname = binary 'john';
+firstname lastname
+john doe
+select * from t1 where firstname='John' and firstname like binary 'john';
+firstname lastname
+john doe
+select * from t1 where firstname='john' and firstname like binary 'John';
+firstname lastname
+John Doe
+drop table t1;
diff --git a/mysql-test/t/binary.test b/mysql-test/t/binary.test
index 95815cda60f..a8c724bf33b 100644
--- a/mysql-test/t/binary.test
+++ b/mysql-test/t/binary.test
@@ -49,3 +49,16 @@ select b from t1 where binary b like '';
select b from t1 group by binary b like '';
select b from t1 having binary b like '';
drop table t1;
+
+#
+# Bug5134: WHERE x = 'bar' AND x LIKE BINARY 'bar' returns wrong results
+#
+
+create table t1( firstname char(20), lastname char(20));
+insert into t1 values ("john","doe"),("John","Doe");
+select * from t1 where firstname='john' and firstname like binary 'john';
+select * from t1 where firstname='john' and binary 'john' = firstname;
+select * from t1 where firstname='john' and firstname = binary 'john';
+select * from t1 where firstname='John' and firstname like binary 'john';
+select * from t1 where firstname='john' and firstname like binary 'John';
+drop table t1;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 882f345a1ca..cf5e8a75f85 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3371,7 +3371,10 @@ change_cond_ref_to_const(I_List<COND_CMP> *save_list,Item *and_father,
Item *right_item= func->arguments()[1];
Item_func::Functype functype= func->functype();
- if (right_item->eq(field,0) && left_item != value)
+ if (right_item->eq(field,0) && left_item != value &&
+ (left_item->result_type() != STRING_RESULT ||
+ value->result_type() != STRING_RESULT ||
+ left_item->binary == value->binary))
{
Item *tmp=value->new_item();
if (tmp)
@@ -3390,7 +3393,10 @@ change_cond_ref_to_const(I_List<COND_CMP> *save_list,Item *and_father,
func->arguments()[1]->result_type()));
}
}
- else if (left_item->eq(field,0) && right_item != value)
+ else if (left_item->eq(field,0) && right_item != value &&
+ (right_item->result_type() != STRING_RESULT ||
+ value->result_type() != STRING_RESULT ||
+ right_item->binary == value->binary))
{
Item *tmp=value->new_item();
if (tmp)