Skip to content

Commit aa1002a

Browse files
author
Alexander Barkov
committed
MDEV-8723 Wrong result for SELECT..WHERE COLLATION(a)='binary' AND a='a'
1 parent 6881012 commit aa1002a

File tree

4 files changed

+79
-13
lines changed

4 files changed

+79
-13
lines changed

mysql-test/r/ctype_binary.result

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,5 +3101,43 @@ Warnings:
31013101
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'a ')
31023102
DROP TABLE t1;
31033103
#
3104+
# MDEV-8723 Wrong result for SELECT..WHERE COLLATION(a)='binary' AND a='a'
3105+
#
3106+
CREATE TABLE t1 (a VARBINARY(10));
3107+
INSERT INTO t1 VALUES ('a'),('A');
3108+
SELECT * FROM t1 WHERE COLLATION(a)='binary' AND a='a';
3109+
a
3110+
a
3111+
SELECT * FROM t1 WHERE CHARSET(a)='binary' AND a='a';
3112+
a
3113+
a
3114+
SELECT * FROM t1 WHERE COERCIBILITY(a)=2 AND a='a';
3115+
a
3116+
a
3117+
SELECT * FROM t1 WHERE WEIGHT_STRING(a)='a' AND a='a';
3118+
a
3119+
a
3120+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COLLATION(a)='binary' AND a='a';
3121+
id select_type table type possible_keys key key_len ref rows filtered Extra
3122+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
3123+
Warnings:
3124+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'a')
3125+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE CHARSET(a)='binary' AND a='a';
3126+
id select_type table type possible_keys key key_len ref rows filtered Extra
3127+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
3128+
Warnings:
3129+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'a')
3130+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COERCIBILITY(a)=2 AND a='a';
3131+
id select_type table type possible_keys key key_len ref rows filtered Extra
3132+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
3133+
Warnings:
3134+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'a')
3135+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE WEIGHT_STRING(a)='a' AND a='a';
3136+
id select_type table type possible_keys key key_len ref rows filtered Extra
3137+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
3138+
Warnings:
3139+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (weight_string(`test`.`t1`.`a`) = 'a'))
3140+
DROP TABLE t1;
3141+
#
31043142
# End of 10.1 tests
31053143
#

mysql-test/t/ctype_binary.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ SELECT * FROM t1 WHERE a='a ' AND LENGTH(a)=2;
5656
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='a ' AND LENGTH(a)=2;
5757
DROP TABLE t1;
5858

59+
--echo #
60+
--echo # MDEV-8723 Wrong result for SELECT..WHERE COLLATION(a)='binary' AND a='a'
61+
--echo #
62+
CREATE TABLE t1 (a VARBINARY(10));
63+
INSERT INTO t1 VALUES ('a'),('A');
64+
SELECT * FROM t1 WHERE COLLATION(a)='binary' AND a='a';
65+
SELECT * FROM t1 WHERE CHARSET(a)='binary' AND a='a';
66+
SELECT * FROM t1 WHERE COERCIBILITY(a)=2 AND a='a';
67+
SELECT * FROM t1 WHERE WEIGHT_STRING(a)='a' AND a='a';
68+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COLLATION(a)='binary' AND a='a';
69+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE CHARSET(a)='binary' AND a='a';
70+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE COERCIBILITY(a)=2 AND a='a';
71+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE WEIGHT_STRING(a)='a' AND a='a';
72+
DROP TABLE t1;
73+
5974
--echo #
6075
--echo # End of 10.1 tests
6176
--echo #

sql/item_func.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,9 @@ class Item_func_coercibility :public Item_int_func
11601160
const char *func_name() const { return "coercibility"; }
11611161
void fix_length_and_dec() { max_length=10; maybe_null= 0; }
11621162
table_map not_null_tables() const { return 0; }
1163+
Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond)
1164+
{ return this; }
1165+
bool const_item() const { return true; }
11631166
};
11641167

11651168
class Item_func_locate :public Item_int_func

sql/item_strfunc.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,36 +1049,44 @@ class Item_func_set_collation :public Item_str_func
10491049
}
10501050
};
10511051

1052-
class Item_func_charset :public Item_str_func
1052+
1053+
class Item_func_expr_str_metadata :public Item_str_func
10531054
{
10541055
public:
1055-
Item_func_charset(THD *thd, Item *a): Item_str_func(thd, a) {}
1056-
String *val_str(String *);
1057-
const char *func_name() const { return "charset"; }
1056+
Item_func_expr_str_metadata(THD *thd, Item *a): Item_str_func(thd, a) { }
10581057
void fix_length_and_dec()
10591058
{
10601059
collation.set(system_charset_info);
10611060
max_length= 64 * collation.collation->mbmaxlen; // should be enough
10621061
maybe_null= 0;
10631062
};
10641063
table_map not_null_tables() const { return 0; }
1064+
Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond)
1065+
{ return this; }
1066+
bool const_item() const { return true; }
10651067
};
10661068

1067-
class Item_func_collation :public Item_str_func
1069+
1070+
class Item_func_charset :public Item_func_expr_str_metadata
10681071
{
10691072
public:
1070-
Item_func_collation(THD *thd, Item *a): Item_str_func(thd, a) {}
1073+
Item_func_charset(THD *thd, Item *a)
1074+
:Item_func_expr_str_metadata(thd, a) { }
1075+
String *val_str(String *);
1076+
const char *func_name() const { return "charset"; }
1077+
};
1078+
1079+
1080+
class Item_func_collation :public Item_func_expr_str_metadata
1081+
{
1082+
public:
1083+
Item_func_collation(THD *thd, Item *a)
1084+
:Item_func_expr_str_metadata(thd, a) {}
10711085
String *val_str(String *);
10721086
const char *func_name() const { return "collation"; }
1073-
void fix_length_and_dec()
1074-
{
1075-
collation.set(system_charset_info);
1076-
max_length= 64 * collation.collation->mbmaxlen; // should be enough
1077-
maybe_null= 0;
1078-
};
1079-
table_map not_null_tables() const { return 0; }
10801087
};
10811088

1089+
10821090
class Item_func_weight_string :public Item_str_func
10831091
{
10841092
String tmp_value;
@@ -1106,6 +1114,8 @@ class Item_func_weight_string :public Item_str_func
11061114
this->nweights == that->nweights &&
11071115
this->result_length == that->result_length;
11081116
}
1117+
Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond)
1118+
{ return this; }
11091119
};
11101120

11111121
class Item_func_crc32 :public Item_int_func

0 commit comments

Comments
 (0)