From 6f302d9f6cb1eafc018d9ca010dc40f15cb19390 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 11 Sep 2015 11:35:15 +0400 Subject: [PATCH] MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types --- mysql-test/r/func_in.result | 24 ++++++++++++++++++++++++ mysql-test/t/func_in.test | 13 +++++++++++++ sql/item_cmpfunc.h | 16 ++++++++-------- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index 51817c24932..33a997c8004 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -812,3 +812,27 @@ EXECUTE s; 1 DROP TABLE t1; # End of 5.3 tests +# +# MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +# Ok to propagate equalities into the left IN argument in case of a single comparison type +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,3); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1) +# Ok to propagate equalities into IN () list, even if multiple comparison types +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND 1 IN (1,a,'3'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1) +# Not Ok to propagate equalities into the left IN argument in case of multiple comparison types +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,'3'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1) and (`test`.`t1`.`a` in (1,2,'3'))) +DROP TABLE t1; diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index 1e695142d90..fab39b04484 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -606,3 +606,16 @@ EXECUTE s; DROP TABLE t1; --echo # End of 5.3 tests + +--echo # +--echo # MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +--echo # Ok to propagate equalities into the left IN argument in case of a single comparison type +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,3); +--echo # Ok to propagate equalities into IN () list, even if multiple comparison types +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND 1 IN (1,a,'3'); +--echo # Not Ok to propagate equalities into the left IN argument in case of multiple comparison types +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,'3'); +DROP TABLE t1; diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index f31c2d033c9..4ea554059ce 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1438,18 +1438,18 @@ public: Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond) { /* - TODO: enable propagation of the args[i>0] arguments even if - !arg_types_compatible. See MDEV-8755. Note, we pass ANY_SUBST, this makes sure that non of the args will be replaced to a zero-filled Item_string. Such a change would require rebuilding of cmp_items. */ - if (arg_types_compatible) - Item_args::propagate_equal_fields(thd, - Context(ANY_SUBST, - m_compare_type, - compare_collation()), - cond); + Context cmpctx(ANY_SUBST, m_compare_type, + Item_func_in::compare_collation()); + for (uint i= 0; i < arg_count; i++) + { + if (arg_types_compatible || i > 0) + args[i]->propagate_equal_fields_and_change_item_tree(thd, cmpctx, + cond, &args[i]); + } return this; } virtual void print(String *str, enum_query_type query_type);