From f8e1952be4cb0736d89a8aed57e872b242a7a2c1 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 28 Nov 2014 18:11:58 +0400 Subject: [PATCH] MDEV-7149 Constant propagation erroneously applied for LIKE Simply disallowing equality propagation into LIKE. A more delicate fix is be possible, but it would need too many changes, which is not desirable in 10.0 at this point. --- .../include/ctype_like_cond_propagation.inc | 39 +++ ...type_like_cond_propagation_utf8_german.inc | 16 ++ mysql-test/r/ctype_binary.result | 95 ++++++ mysql-test/r/ctype_latin1.result | 192 +++++++++++++ mysql-test/r/ctype_uca.result | 270 ++++++++++++++++++ mysql-test/r/ctype_ucs.result | 193 +++++++++++++ mysql-test/r/ctype_utf8.result | 229 +++++++++++++++ mysql-test/t/ctype_binary.test | 12 + mysql-test/t/ctype_latin1.test | 7 + mysql-test/t/ctype_uca.test | 8 + mysql-test/t/ctype_ucs.test | 6 + mysql-test/t/ctype_utf8.test | 7 + sql/item_cmpfunc.h | 37 ++- 13 files changed, 1110 insertions(+), 1 deletion(-) create mode 100644 mysql-test/include/ctype_like_cond_propagation.inc create mode 100644 mysql-test/include/ctype_like_cond_propagation_utf8_german.inc diff --git a/mysql-test/include/ctype_like_cond_propagation.inc b/mysql-test/include/ctype_like_cond_propagation.inc new file mode 100644 index 00000000000..023cf2b1b30 --- /dev/null +++ b/mysql-test/include/ctype_like_cond_propagation.inc @@ -0,0 +1,39 @@ +--echo # +--echo # MDEV-7149 Constant condition propagation erroneously applied for LIKE +--echo # + +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +DROP TABLE t1; diff --git a/mysql-test/include/ctype_like_cond_propagation_utf8_german.inc b/mysql-test/include/ctype_like_cond_propagation_utf8_german.inc new file mode 100644 index 00000000000..2cfa89448bc --- /dev/null +++ b/mysql-test/include/ctype_like_cond_propagation_utf8_german.inc @@ -0,0 +1,16 @@ +--echo # +--echo # MDEV-7149 Constant condition propagation erroneously applied for LIKE +--echo # + +CREATE TABLE t1 AS SELECT REPEAT('a',10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('ae'),('ä'); +SELECT * FROM t1 WHERE c1='ä'; +SELECT * FROM t1 WHERE c1 LIKE 'ae'; +SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +SELECT * FROM t1 WHERE CONCAT(c1)='ä'; +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'ae'; +SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +DROP TABLE IF EXISTS t1; diff --git a/mysql-test/r/ctype_binary.result b/mysql-test/r/ctype_binary.result index 550c47ccdaa..f35e6fd8265 100644 --- a/mysql-test/r/ctype_binary.result +++ b/mysql-test/r/ctype_binary.result @@ -2915,3 +2915,98 @@ SET sql_mode=default; # # End of 5.5 tests # +# +# Start of 10.0 tests +# +SET NAMES binary; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varbinary(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where 0 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varbinary(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where 0 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varbinary(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where 0 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varbinary(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where ('%' = concat(`test`.`t1`.`c1`)) +DROP TABLE t1; +# +# End of 10.0 tests +# diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index fac9824401f..970c067b25c 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -7659,6 +7659,198 @@ DROP FUNCTION mysql_real_escape_string_generated; DROP FUNCTION iswellformed; DROP TABLE allbytes; # End of ctype_backslash.inc +SET NAMES latin1; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +SET NAMES latin1 COLLATE latin1_bin; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; # # MDEV-6752 Trailing incomplete characters are not replaced to question marks on conversion # diff --git a/mysql-test/r/ctype_uca.result b/mysql-test/r/ctype_uca.result index c947689ef81..94db9d8f783 100644 --- a/mysql-test/r/ctype_uca.result +++ b/mysql-test/r/ctype_uca.result @@ -7700,6 +7700,276 @@ DROP TABLE t1; # Start of MariaDB-10.0 tests # +SET NAMES utf8 COLLATE utf8_unicode_ci; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a',10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('ae'),('ä'); +SELECT * FROM t1 WHERE c1='ä'; +c1 +ä +SELECT * FROM t1 WHERE c1 LIKE 'ae'; +c1 +ae +SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +c1 +EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +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`.`c1` AS `c1` from `test`.`t1` where ((`test`.`t1`.`c1` = 'ä') and (`test`.`t1`.`c1` like 'ae')) +SELECT * FROM t1 WHERE CONCAT(c1)='ä'; +c1 +ä +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'ae'; +c1 +ae +SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +c1 +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'ä') and (concat(`test`.`t1`.`c1`) like 'ae')) +DROP TABLE IF EXISTS t1; +SET NAMES utf8 COLLATE utf8_german2_ci; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_german2_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_german2_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_german2_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_german2_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a',10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_german2_ci NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('ae'),('ä'); +SELECT * FROM t1 WHERE c1='ä'; +c1 +ae +ä +SELECT * FROM t1 WHERE c1 LIKE 'ae'; +c1 +ae +SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +c1 +ae +EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +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`.`c1` AS `c1` from `test`.`t1` where ((`test`.`t1`.`c1` = 'ä') and (`test`.`t1`.`c1` like 'ae')) +SELECT * FROM t1 WHERE CONCAT(c1)='ä'; +c1 +ae +ä +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'ae'; +c1 +ae +SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +c1 +ae +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'ä') and (concat(`test`.`t1`.`c1`) like 'ae')) +DROP TABLE IF EXISTS t1; # # MDEV-4929 Myanmar collation # diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index 3cfc076b8a0..68435f3f41c 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -5326,6 +5326,199 @@ DROP TABLE t1; # # Start of 10.0 tests # +SET NAMES latin1, collation_connection=ucs2_bin; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 COLLATE ucs2_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 COLLATE ucs2_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 COLLATE ucs2_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 COLLATE ucs2_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +SET NAMES latin1, collation_connection=ucs2_general_ci; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET ucs2 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +SET NAMES latin1; # # MDEV-6661 PI() does not work well in UCS2/UTF16/UTF32 context # diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 43f3aa4b6c9..c752024ec7f 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -5936,6 +5936,235 @@ set max_sort_length=default; # # Start of 10.0 tests # +SET NAMES utf8 COLLATE utf8_bin; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +SET NAMES utf8; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE CONCAT(c1)='a'; +c1 +a +a +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'a '; +c1 +a +SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='a' AND CONCAT(c1) LIKE 'a '; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'a') and (concat(`test`.`t1`.`c1`) like 'a ')) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT * FROM t1 WHERE 'a'=CONCAT(c1); +c1 +a +a +SELECT * FROM t1 WHERE 'a ' LIKE CONCAT(c1); +c1 +a +SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +c1 +a +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 'a'=CONCAT(c1) AND 'a ' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('a' = concat(`test`.`t1`.`c1`)) and ('a ' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '% '=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '% '=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('% ' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +CREATE TABLE t1 AS SELECT REPEAT('a', 10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('%'),('% '); +SELECT * FROM t1 WHERE '%'=CONCAT(c1); +c1 +% +% +SELECT * FROM t1 WHERE 'a' LIKE CONCAT(c1); +c1 +% +SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +c1 +% +EXPLAIN EXTENDED SELECT * FROM t1 WHERE '%'=CONCAT(c1) AND 'a' LIKE CONCAT(c1); +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`.`c1` AS `c1` from `test`.`t1` where (('%' = concat(`test`.`t1`.`c1`)) and ('a' like concat(`test`.`t1`.`c1`))) +DROP TABLE t1; +# +# MDEV-7149 Constant condition propagation erroneously applied for LIKE +# +CREATE TABLE t1 AS SELECT REPEAT('a',10) AS c1 LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('ae'),('ä'); +SELECT * FROM t1 WHERE c1='ä'; +c1 +ä +SELECT * FROM t1 WHERE c1 LIKE 'ae'; +c1 +ae +SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +c1 +EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1='ä' AND c1 LIKE 'ae'; +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`.`c1` AS `c1` from `test`.`t1` where ((`test`.`t1`.`c1` = 'ä') and (`test`.`t1`.`c1` like 'ae')) +SELECT * FROM t1 WHERE CONCAT(c1)='ä'; +c1 +ä +SELECT * FROM t1 WHERE CONCAT(c1) LIKE 'ae'; +c1 +ae +SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +c1 +EXPLAIN EXTENDED SELECT * FROM t1 WHERE CONCAT(c1)='ä' AND CONCAT(c1) LIKE 'ae'; +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`.`c1` AS `c1` from `test`.`t1` where ((concat(`test`.`t1`.`c1`) = 'ä') and (concat(`test`.`t1`.`c1`) like 'ae')) +DROP TABLE IF EXISTS t1; # # MDEV-6666 Malformed result for CONCAT(utf8_column, binary_string) # diff --git a/mysql-test/t/ctype_binary.test b/mysql-test/t/ctype_binary.test index 8b57854de83..4a2646d1db5 100644 --- a/mysql-test/t/ctype_binary.test +++ b/mysql-test/t/ctype_binary.test @@ -10,3 +10,15 @@ set names binary; --echo # --echo # End of 5.5 tests --echo # + + +--echo # +--echo # Start of 10.0 tests +--echo # + +SET NAMES binary; +--source include/ctype_like_cond_propagation.inc + +--echo # +--echo # End of 10.0 tests +--echo # diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test index 5da1534029b..336d8ca761d 100644 --- a/mysql-test/t/ctype_latin1.test +++ b/mysql-test/t/ctype_latin1.test @@ -210,6 +210,13 @@ set names latin1; let $ctype_unescape_combinations=selected; --source include/ctype_unescape.inc +SET NAMES latin1; +--source include/ctype_like_cond_propagation.inc + +SET NAMES latin1 COLLATE latin1_bin; +--source include/ctype_like_cond_propagation.inc + + --echo # --echo # MDEV-6752 Trailing incomplete characters are not replaced to question marks on conversion --echo # diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test index 79f163d7e5d..fa33535c9b1 100644 --- a/mysql-test/t/ctype_uca.test +++ b/mysql-test/t/ctype_uca.test @@ -571,6 +571,14 @@ SET NAMES utf8mb4 COLLATE utf8mb4_unicode_520_ci; --echo # --echo +SET NAMES utf8 COLLATE utf8_unicode_ci; +--source include/ctype_like_cond_propagation.inc +--source include/ctype_like_cond_propagation_utf8_german.inc + +SET NAMES utf8 COLLATE utf8_german2_ci; +--source include/ctype_like_cond_propagation.inc +--source include/ctype_like_cond_propagation_utf8_german.inc + --echo # --echo # MDEV-4929 Myanmar collation --echo # diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index d269fb35dfe..33d41e9bc4c 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -897,6 +897,12 @@ DROP TABLE t1; --echo # Start of 10.0 tests --echo # +SET NAMES latin1, collation_connection=ucs2_bin; +--source include/ctype_like_cond_propagation.inc +SET NAMES latin1, collation_connection=ucs2_general_ci; +--source include/ctype_like_cond_propagation.inc +SET NAMES latin1; + --echo # --echo # MDEV-6661 PI() does not work well in UCS2/UTF16/UTF32 context --echo # diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index e02d5a915b7..1e9047cca8e 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1658,6 +1658,13 @@ set max_sort_length=default; --echo # Start of 10.0 tests --echo # +SET NAMES utf8 COLLATE utf8_bin; +--source include/ctype_like_cond_propagation.inc +SET NAMES utf8; +--source include/ctype_like_cond_propagation.inc +--source include/ctype_like_cond_propagation_utf8_german.inc + + --echo # --echo # MDEV-6666 Malformed result for CONCAT(utf8_column, binary_string) --echo # diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 8e2b8a9fd6a..affed52cfd2 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1486,7 +1486,42 @@ public: longlong val_int(); enum Functype functype() const { return LIKE_FUNC; } optimize_type select_optimize() const; - cond_result eq_cmp_result() const { return COND_TRUE; } + cond_result eq_cmp_result() const + { + /** + We cannot always rewrite conditions as follows: + from: WHERE expr1=const AND expr1 LIKE expr2 + to: WHERE expr1=const AND const LIKE expr2 + or + from: WHERE expr1=const AND expr2 LIKE expr1 + to: WHERE expr1=const AND expr2 LIKE const + + because LIKE works differently comparing to the regular "=" operator: + + 1. LIKE performs a stricter one-character-to-one-character comparison + and does not recognize contractions and expansions. + Replacing "expr1" to "const in LIKE would make the condition + stricter in case of a complex collation. + + 2. LIKE does not ignore trailing spaces and thus works differently + from the "=" operator in case of "PAD SPACE" collations + (which are the majority in MariaDB). So, for "PAD SPACE" collations: + + - expr1=const - ignores trailing spaces + - const LIKE expr2 - does not ignore trailing spaces + - expr2 LIKE const - does not ignore trailing spaces + + Allow only "binary" for now. + It neither ignores trailing spaces nor has contractions/expansions. + + TODO: + We could still replace "expr1" to "const" in "expr1 LIKE expr2" + in case of a "PAD SPACE" collation, but only if "expr2" has '%' + at the end. + */ + return ((Item_func_like *)this)->compare_collation() == &my_charset_bin ? + COND_TRUE : COND_OK; + } const char *func_name() const { return "like"; } bool fix_fields(THD *thd, Item **ref); void cleanup();