From 7f905da3d835307b8bc0ab8df864486e3c2e1c18 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Feb 2005 21:17:20 -0800 Subject: [PATCH] select.result, select.test: Added a test case for bug #7098. sql_select.cc: Fixed bug #7098. When a string field was substituted for an equal constant the collation of the constant was changed by mistake for the binary collation. sql/sql_select.cc: Fixed bug #7098. When a string field was substituted for an equal constant the collation of the constant was changed by mistake for the binary collation. mysql-test/t/select.test: Added a test case for bug #7098. mysql-test/r/select.result: Added a test case for bug #7098. --- mysql-test/r/select.result | 22 ++++++++++++++++++++++ mysql-test/t/select.test | 19 +++++++++++++++++++ sql/sql_select.cc | 4 ++++ 3 files changed, 45 insertions(+) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 70ac33964ad..1a3b2ab22e6 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2400,3 +2400,25 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t2 ref a a 23 test.t1.a 2 DROP TABLE t1, t2; +CREATE TABLE t1 ( city char(30) ); +INSERT INTO t1 VALUES ('London'); +INSERT INTO t1 VALUES ('Paris'); +SELECT * FROM t1 WHERE city='London'; +city +London +SELECT * FROM t1 WHERE city='london'; +city +London +EXPLAIN SELECT * FROM t1 WHERE city='London' AND city='london'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +SELECT * FROM t1 WHERE city='London' AND city='london'; +city +London +EXPLAIN SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London'; +city +London +DROP TABLE t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index c00395d95e7..53f569c773e 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -1945,3 +1945,22 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a; EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a; DROP TABLE t1, t2; + + +# +# Test case for bug 7098: substitution of a constant for a string field +# + +CREATE TABLE t1 ( city char(30) ); +INSERT INTO t1 VALUES ('London'); +INSERT INTO t1 VALUES ('Paris'); + +SELECT * FROM t1 WHERE city='London'; +SELECT * FROM t1 WHERE city='london'; +EXPLAIN SELECT * FROM t1 WHERE city='London' AND city='london'; +SELECT * FROM t1 WHERE city='London' AND city='london'; +EXPLAIN SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London'; +SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London'; + +DROP TABLE t1; + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 05314097ca3..21e197d432b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4230,6 +4230,8 @@ change_cond_ref_to_const(THD *thd, I_List *save_list, Item *tmp=value->new_item(); if (tmp) { + tmp->collation.set(value->collation.collation, + value->collation.derivation); thd->change_item_tree(args + 1, tmp); func->update_used_tables(); if ((functype == Item_func::EQ_FUNC || functype == Item_func::EQUAL_FUNC) @@ -4251,6 +4253,8 @@ change_cond_ref_to_const(THD *thd, I_List *save_list, Item *tmp=value->new_item(); if (tmp) { + tmp->collation.set(value->collation.collation, + value->collation.derivation); thd->change_item_tree(args, tmp); value= tmp; func->update_used_tables();