Commit 68810129 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-8695 Wrong result for SELECT..WHERE varchar_column='a' AND CRC32(varchar_column)=3904355907

parent 4f0255cb
...@@ -3041,3 +3041,65 @@ _binary 0x7E _binary X'7E' _binary B'01111110' ...@@ -3041,3 +3041,65 @@ _binary 0x7E _binary X'7E' _binary B'01111110'
# #
# End of 10.0 tests # End of 10.0 tests
# #
#
# Start of 10.1 tests
#
#
# MDEV-8695 Wrong result for SELECT..WHERE varchar_column='a' AND CRC32(varchar_column)=3904355907
#
CREATE TABLE t1 (a VARBINARY(10));
INSERT INTO t1 VALUES ('a'),('a ');
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE CRC32(a)=3904355907;
a LENGTH(a) CRC32(a)
a 1 3904355907
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
a LENGTH(a) CRC32(a)
a 1 3904355907
# Okey to propagate 'a' into CRC32(a)
EXPLAIN EXTENDED SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
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`,length(`test`.`t1`.`a`) AS `LENGTH(a)`,crc32(`test`.`t1`.`a`) AS `CRC32(a)` from `test`.`t1` where (`test`.`t1`.`a` = 'a')
SELECT a, HEX(a) FROM t1 WHERE HEX(a)='61';
a HEX(a)
a 61
SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
a HEX(a)
a 61
# Okey to propagate 'a' into HEX(a)
EXPLAIN EXTENDED SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
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`,hex(`test`.`t1`.`a`) AS `HEX(a)` from `test`.`t1` where (`test`.`t1`.`a` = 'a')
SELECT * FROM t1 WHERE a='a';
a
a
SELECT * FROM t1 WHERE LENGTH(a)=2;
a
a
SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
a
# Okey to propagate 'a' into LENGTH(a)
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
SELECT * FROM t1 WHERE a='a ';
a
a
SELECT * FROM t1 WHERE a='a ' AND LENGTH(a)=2;
a
a
# Okey to propagate 'a ' into LENGTH(a)
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='a ' AND LENGTH(a)=2;
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` = 'a ')
DROP TABLE t1;
#
# End of 10.1 tests
#
...@@ -8103,5 +8103,51 @@ SELECT * FROM t1 WHERE a=b AND a=DATE'2001-01-01'; ...@@ -8103,5 +8103,51 @@ SELECT * FROM t1 WHERE a=b AND a=DATE'2001-01-01';
a b a b
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-8695 Wrong result for SELECT..WHERE varchar_column='a' AND CRC32(varchar_column)=3904355907
#
CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_bin);
INSERT INTO t1 VALUES ('a'),('a ');
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE CRC32(a)=3904355907;
a LENGTH(a) CRC32(a)
a 1 3904355907
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
a LENGTH(a) CRC32(a)
a 1 3904355907
# 'a' should not be propagated into CRC32(a)
EXPLAIN EXTENDED SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
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`,length(`test`.`t1`.`a`) AS `LENGTH(a)`,crc32(`test`.`t1`.`a`) AS `CRC32(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (crc32(`test`.`t1`.`a`) = 3904355907))
SELECT a, HEX(a) FROM t1 WHERE HEX(a)='61';
a HEX(a)
a 61
SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
a HEX(a)
a 61
# 'a' should not be propagated into HEX(a)
EXPLAIN EXTENDED SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
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`,hex(`test`.`t1`.`a`) AS `HEX(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (hex(`test`.`t1`.`a`) = '61'))
SELECT * FROM t1 WHERE a='a';
a
a
a
SELECT * FROM t1 WHERE LENGTH(a)=2;
a
a
SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
a
a
# 'a' should not be propagated into LENGTH(a)
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
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` = 'a') and (length(`test`.`t1`.`a`) = 2))
DROP TABLE t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -27,3 +27,35 @@ SELECT _binary 0x7E, _binary X'7E', _binary B'01111110'; ...@@ -27,3 +27,35 @@ SELECT _binary 0x7E, _binary X'7E', _binary B'01111110';
--echo # --echo #
--echo # End of 10.0 tests --echo # End of 10.0 tests
--echo # --echo #
--echo #
--echo # Start of 10.1 tests
--echo #
--echo #
--echo # MDEV-8695 Wrong result for SELECT..WHERE varchar_column='a' AND CRC32(varchar_column)=3904355907
--echo #
CREATE TABLE t1 (a VARBINARY(10));
INSERT INTO t1 VALUES ('a'),('a ');
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE CRC32(a)=3904355907;
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
--echo # Okey to propagate 'a' into CRC32(a)
EXPLAIN EXTENDED SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
SELECT a, HEX(a) FROM t1 WHERE HEX(a)='61';
SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
--echo # Okey to propagate 'a' into HEX(a)
EXPLAIN EXTENDED SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
SELECT * FROM t1 WHERE a='a';
SELECT * FROM t1 WHERE LENGTH(a)=2;
SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
--echo # Okey to propagate 'a' into LENGTH(a)
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
SELECT * FROM t1 WHERE a='a ';
SELECT * FROM t1 WHERE a='a ' AND LENGTH(a)=2;
--echo # Okey to propagate 'a ' into LENGTH(a)
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='a ' AND LENGTH(a)=2;
DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #
...@@ -329,6 +329,27 @@ INSERT INTO t1 VALUES ('2001-01-01','2001-01-01x'); ...@@ -329,6 +329,27 @@ INSERT INTO t1 VALUES ('2001-01-01','2001-01-01x');
SELECT * FROM t1 WHERE a=b AND a=DATE'2001-01-01'; SELECT * FROM t1 WHERE a=b AND a=DATE'2001-01-01';
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-8695 Wrong result for SELECT..WHERE varchar_column='a' AND CRC32(varchar_column)=3904355907
--echo #
CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_bin);
INSERT INTO t1 VALUES ('a'),('a ');
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE CRC32(a)=3904355907;
SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
--echo # 'a' should not be propagated into CRC32(a)
EXPLAIN EXTENDED SELECT a, LENGTH(a), CRC32(a) FROM t1 WHERE a='a' AND CRC32(a)=3904355907;
SELECT a, HEX(a) FROM t1 WHERE HEX(a)='61';
SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
--echo # 'a' should not be propagated into HEX(a)
EXPLAIN EXTENDED SELECT *,HEX(a) FROM t1 WHERE a='a' AND HEX(a)='61';
SELECT * FROM t1 WHERE a='a';
SELECT * FROM t1 WHERE LENGTH(a)=2;
SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
--echo # 'a' should not be propagated into LENGTH(a)
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='a' AND LENGTH(a)=2;
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -5368,9 +5368,10 @@ bool Item_field::can_be_substituted_to_equal_item(const Context &ctx, ...@@ -5368,9 +5368,10 @@ bool Item_field::can_be_substituted_to_equal_item(const Context &ctx,
if (cmp_context == STRING_RESULT && if (cmp_context == STRING_RESULT &&
ctx.compare_collation() != item_equal->compare_collation()) ctx.compare_collation() != item_equal->compare_collation())
return false; return false;
return (ctx.subst_constraint() == ANY_SUBST || return ctx.subst_constraint() == ANY_SUBST ||
field->result_type() != STRING_RESULT || field->cmp_type() != STRING_RESULT ||
(field->flags & BINARY_FLAG)); ((field->charset()->state & MY_CS_BINSORT) &&
(field->charset()->state & MY_CS_NOPAD));
} }
......
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