Skip to content

Commit 6f302d9

Browse files
author
Alexander Barkov
committed
MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types
1 parent 0302efc commit 6f302d9

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

mysql-test/r/func_in.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,3 +812,27 @@ EXECUTE s;
812812
1
813813
DROP TABLE t1;
814814
# End of 5.3 tests
815+
#
816+
# MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types
817+
#
818+
CREATE TABLE t1 (a INT);
819+
INSERT INTO t1 VALUES (1),(2);
820+
# Ok to propagate equalities into the left IN argument in case of a single comparison type
821+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,3);
822+
id select_type table type possible_keys key key_len ref rows filtered Extra
823+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
824+
Warnings:
825+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1)
826+
# Ok to propagate equalities into IN () list, even if multiple comparison types
827+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND 1 IN (1,a,'3');
828+
id select_type table type possible_keys key key_len ref rows filtered Extra
829+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
830+
Warnings:
831+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1)
832+
# Not Ok to propagate equalities into the left IN argument in case of multiple comparison types
833+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,'3');
834+
id select_type table type possible_keys key key_len ref rows filtered Extra
835+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
836+
Warnings:
837+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 1) and (`test`.`t1`.`a` in (1,2,'3')))
838+
DROP TABLE t1;

mysql-test/t/func_in.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,16 @@ EXECUTE s;
606606
DROP TABLE t1;
607607

608608
--echo # End of 5.3 tests
609+
610+
--echo #
611+
--echo # MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types
612+
--echo #
613+
CREATE TABLE t1 (a INT);
614+
INSERT INTO t1 VALUES (1),(2);
615+
--echo # Ok to propagate equalities into the left IN argument in case of a single comparison type
616+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,3);
617+
--echo # Ok to propagate equalities into IN () list, even if multiple comparison types
618+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND 1 IN (1,a,'3');
619+
--echo # Not Ok to propagate equalities into the left IN argument in case of multiple comparison types
620+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,'3');
621+
DROP TABLE t1;

sql/item_cmpfunc.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,18 +1438,18 @@ class Item_func_in :public Item_func_opt_neg
14381438
Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond)
14391439
{
14401440
/*
1441-
TODO: enable propagation of the args[i>0] arguments even if
1442-
!arg_types_compatible. See MDEV-8755.
14431441
Note, we pass ANY_SUBST, this makes sure that non of the args
14441442
will be replaced to a zero-filled Item_string.
14451443
Such a change would require rebuilding of cmp_items.
14461444
*/
1447-
if (arg_types_compatible)
1448-
Item_args::propagate_equal_fields(thd,
1449-
Context(ANY_SUBST,
1450-
m_compare_type,
1451-
compare_collation()),
1452-
cond);
1445+
Context cmpctx(ANY_SUBST, m_compare_type,
1446+
Item_func_in::compare_collation());
1447+
for (uint i= 0; i < arg_count; i++)
1448+
{
1449+
if (arg_types_compatible || i > 0)
1450+
args[i]->propagate_equal_fields_and_change_item_tree(thd, cmpctx,
1451+
cond, &args[i]);
1452+
}
14531453
return this;
14541454
}
14551455
virtual void print(String *str, enum_query_type query_type);

0 commit comments

Comments
 (0)