Commit a4b0063d authored by Alexander Barkov's avatar Alexander Barkov

MDEV-8256 A part of a ROW comparison is erroneously optimized away

Item_func_eq's created during conversion of a ROW equality to a conjunction
of scalar equalities did not set cmp_context for its arguments properly,
so some of these created Item_func_eq could be later erroneously eliminated.
parent 4a7afdde
...@@ -9970,5 +9970,36 @@ SET NAMES utf8; ...@@ -9970,5 +9970,36 @@ SET NAMES utf8;
SELECT * FROM `test😁😁test`; SELECT * FROM `test😁😁test`;
ERROR HY000: Invalid utf8 character string: 'test\xF0\x9F\x98\x81\xF0\x9F\x98\x81test' ERROR HY000: Invalid utf8 character string: 'test\xF0\x9F\x98\x81\xF0\x9F\x98\x81test'
# #
#MDEV-8256 A part of a ROW comparison is erroneously optimized away
#
SET NAMES utf8;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8);
INSERT INTO t1 VALUES ('1e1'),('1é1');
SELECT * FROM t1 WHERE a=10;
a
1e1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: '1é1'
SELECT * FROM t1 WHERE a='1e1';
a
1e1
1é1
SELECT * FROM t1 WHERE a=10 AND a='1e1';
a
1e1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: '1é1'
SELECT * FROM t1 WHERE (a,a)=(10,'1e1');
a
1e1
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: '1é1'
EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a,a)=(10,'1e1');
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` = 10) and (`test`.`t1`.`a` = '1e1'))
DROP TABLE t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -1789,6 +1789,20 @@ SET NAMES utf8; ...@@ -1789,6 +1789,20 @@ SET NAMES utf8;
--error ER_INVALID_CHARACTER_STRING --error ER_INVALID_CHARACTER_STRING
SELECT * FROM `test😁😁test`; SELECT * FROM `test😁😁test`;
--echo #
--echo #MDEV-8256 A part of a ROW comparison is erroneously optimized away
--echo #
SET NAMES utf8;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8);
INSERT INTO t1 VALUES ('1e1'),('1é1');
SELECT * FROM t1 WHERE a=10;
SELECT * FROM t1 WHERE a='1e1';
SELECT * FROM t1 WHERE a=10 AND a='1e1';
SELECT * FROM t1 WHERE (a,a)=(10,'1e1');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a,a)=(10,'1e1');
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -325,6 +325,14 @@ class Item_bool_rowready_func2 :public Item_bool_func2 ...@@ -325,6 +325,14 @@ class Item_bool_rowready_func2 :public Item_bool_func2
{ {
return cmp.set_cmp_func(this, tmp_arg, tmp_arg + 1, true); return cmp.set_cmp_func(this, tmp_arg, tmp_arg + 1, true);
} }
bool set_cmp_func_and_arg_cmp_context()
{
if (set_cmp_func())
return true;
tmp_arg[0]->cmp_context= tmp_arg[1]->cmp_context=
item_cmp_type(tmp_arg[0]->result_type(), tmp_arg[1]->result_type());
return false;
}
CHARSET_INFO *compare_collation() const CHARSET_INFO *compare_collation() const
{ return cmp.cmp_collation.collation; } { return cmp.cmp_collation.collation; }
Arg_comparator *get_comparator() { return &cmp; } Arg_comparator *get_comparator() { return &cmp; }
......
...@@ -12566,7 +12566,7 @@ static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item, ...@@ -12566,7 +12566,7 @@ static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item,
Item_func_eq *eq_item; Item_func_eq *eq_item;
if (!(eq_item= new (thd->mem_root) Item_func_eq(orig_left_item, if (!(eq_item= new (thd->mem_root) Item_func_eq(orig_left_item,
orig_right_item)) || orig_right_item)) ||
eq_item->set_cmp_func()) eq_item->set_cmp_func_and_arg_cmp_context())
return FALSE; return FALSE;
eq_item->quick_fix_field(); eq_item->quick_fix_field();
item= eq_item; item= eq_item;
...@@ -12660,7 +12660,7 @@ static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row, ...@@ -12660,7 +12660,7 @@ static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row,
{ {
Item_func_eq *eq_item; Item_func_eq *eq_item;
if (!(eq_item= new Item_func_eq(left_item, right_item)) || if (!(eq_item= new Item_func_eq(left_item, right_item)) ||
eq_item->set_cmp_func()) eq_item->set_cmp_func_and_arg_cmp_context())
return FALSE; return FALSE;
eq_item->quick_fix_field(); eq_item->quick_fix_field();
eq_list->push_back(eq_item); eq_list->push_back(eq_item);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment