diff --git a/include/m_ctype.h b/include/m_ctype.h index c5be24bb063..a55222682b0 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -201,6 +201,10 @@ extern MY_UNI_CTYPE my_uni_ctype[256]; #define MY_CS_UNICODE_SUPPLEMENT 16384 /* Non-BMP Unicode characters */ #define MY_CS_LOWER_SORT 32768 /* If use lower case as weight */ #define MY_CS_STRNXFRM_BAD_NWEIGHTS 0x10000 /* strnxfrm ignores "nweights" */ +#define MY_CS_NOPAD 0x20000 /* if does not ignore trailing spaces */ +#define MY_CS_NON1TO1 0x40000 /* Has a complex mapping from characters + to weights, e.g. contractions, expansions, + ignorable characters */ #define MY_CHARSET_UNDEFINED 0 /* Character repertoire flags */ diff --git a/mysql-test/include/ctype_like_cond_propagation.inc b/mysql-test/include/ctype_like_cond_propagation.inc index 023cf2b1b30..1c6ea04ded2 100644 --- a/mysql-test/include/ctype_like_cond_propagation.inc +++ b/mysql-test/include/ctype_like_cond_propagation.inc @@ -37,3 +37,19 @@ 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; + +--echo # +--echo # MDEV-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +--echo # + +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +DROP TABLE t1; + +--echo # +--echo # End of MDEV-8694 +--echo # diff --git a/mysql-test/r/ctype_binary.result b/mysql-test/r/ctype_binary.result index 8e589c5b90a..ec143d6ff35 100644 --- a/mysql-test/r/ctype_binary.result +++ b/mysql-test/r/ctype_binary.result @@ -3008,6 +3008,31 @@ Warnings: Note 1003 select `test`.`t1`.`c1` AS `c1` from `test`.`t1` where ('%' = concat(`test`.`t1`.`c1`)) DROP TABLE t1; # +# MDEV-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varbinary(10) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where (`test`.`t1`.`a` = 'a') +DROP TABLE t1; +# +# End of MDEV-8694 +# +# # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 # SELECT _binary 0x7E, _binary X'7E', _binary B'01111110'; diff --git a/mysql-test/r/ctype_cp1250_ch.result b/mysql-test/r/ctype_cp1250_ch.result index 3dfd97d2c25..f2eeb4dda79 100644 --- a/mysql-test/r/ctype_cp1250_ch.result +++ b/mysql-test/r/ctype_cp1250_ch.result @@ -105,6 +105,126 @@ SET character_set_server= @safe_character_set_server; SET collation_server= @safe_collation_server; SET character_set_client= @safe_character_set_client; SET character_set_results= @safe_character_set_results; +# +# 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 +) 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 +) 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 +) 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 +) 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET utf8 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((not((`test`.`t1`.`a` like 'a '))) and (`test`.`t1`.`a` = 'a')) +DROP TABLE t1; +# +# End of MDEV-8694 +# SET @test_character_set= 'cp1250'; SET @test_collation= 'cp1250_czech_cs'; SET @safe_character_set_server= @@character_set_server; diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index df492800147..4c5b00593cd 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -7755,6 +7755,31 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# SET NAMES latin1 COLLATE latin1_bin; # # MDEV-7149 Constant condition propagation erroneously applied for LIKE @@ -7852,6 +7877,31 @@ 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# +# # MDEV-6752 Trailing incomplete characters are not replaced to question marks on conversion # SET NAMES utf8, character_set_connection=latin1; diff --git a/mysql-test/r/ctype_latin2_ch.result b/mysql-test/r/ctype_latin2_ch.result index 0cad7a0e350..6e73affeef6 100644 --- a/mysql-test/r/ctype_latin2_ch.result +++ b/mysql-test/r/ctype_latin2_ch.result @@ -45,6 +45,126 @@ strcmp('a\t','a' ) SELECT strcmp('a\t','a '); strcmp('a\t','a ') 0 +# +# 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 latin2 COLLATE latin2_czech_cs NOT NULL +) 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 latin2 COLLATE latin2_czech_cs NOT NULL +) 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 latin2 COLLATE latin2_czech_cs NOT NULL +) 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 latin2 COLLATE latin2_czech_cs NOT NULL +) 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET latin2 COLLATE latin2_czech_cs NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# create table t1 ( a varchar(2) character set latin2 collate latin2_czech_cs, primary key(a) diff --git a/mysql-test/r/ctype_tis620.result b/mysql-test/r/ctype_tis620.result index 88724d44d7c..947aeb5ff5b 100644 --- a/mysql-test/r/ctype_tis620.result +++ b/mysql-test/r/ctype_tis620.result @@ -3115,6 +3115,126 @@ Zz 5A,7A ~ 7E  7F 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 tis620 NOT NULL +) 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 tis620 NOT NULL +) 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 tis620 NOT NULL +) 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 tis620 NOT NULL +) 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET tis620 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# SET collation_connection='tis620_bin'; create table t1 select repeat('a',4000) a; delete from t1; @@ -3212,6 +3332,126 @@ c2h ab_def 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 tis620 COLLATE tis620_bin NOT NULL +) 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 tis620 COLLATE tis620_bin NOT NULL +) 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 tis620 COLLATE tis620_bin NOT NULL +) 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 tis620 COLLATE tis620_bin NOT NULL +) 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET tis620 COLLATE tis620_bin NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# +# # Start of 5.6 tests # # diff --git a/mysql-test/r/ctype_uca.result b/mysql-test/r/ctype_uca.result index 98595230d2f..51f37d13aa7 100644 --- a/mysql-test/r/ctype_uca.result +++ b/mysql-test/r/ctype_uca.result @@ -8285,6 +8285,31 @@ 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((not((`test`.`t1`.`a` like 'a '))) and (`test`.`t1`.`a` = 'a')) +DROP TABLE t1; +# +# End of MDEV-8694 +# +# # MDEV-7149 Constant condition propagation erroneously applied for LIKE # CREATE TABLE t1 AS SELECT REPEAT('a',10) AS c1 LIMIT 0; @@ -8418,6 +8443,31 @@ 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET utf8 COLLATE utf8_german2_ci NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((not((`test`.`t1`.`a` like 'a '))) and (`test`.`t1`.`a` = 'a')) +DROP TABLE t1; +# +# End of MDEV-8694 +# +# # MDEV-7149 Constant condition propagation erroneously applied for LIKE # CREATE TABLE t1 AS SELECT REPEAT('a',10) AS c1 LIMIT 0; diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index b9dc74f64cd..ad08359bd9c 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -5446,6 +5446,31 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET ucs2 COLLATE ucs2_bin NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 2 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 2 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# SET NAMES latin1, collation_connection=ucs2_general_ci; # # MDEV-7149 Constant condition propagation erroneously applied for LIKE @@ -5542,6 +5567,31 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET ucs2 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 2 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 2 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# 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 e04ce65d831..c20680a2a3e 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -6775,6 +6775,31 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (not((`test`.`t1`.`a` like 'a ')))) +DROP TABLE t1; +# +# End of MDEV-8694 +# SET NAMES utf8; # # MDEV-7149 Constant condition propagation erroneously applied for LIKE @@ -6872,6 +6897,31 @@ 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-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' +# +CREATE TABLE t1 AS SELECT SPACE(10) AS a LIMIT 0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(10) CHARACTER SET utf8 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES ('a'),('a '); +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a '; +a LENGTH(a) +a 1 +SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a'; +a LENGTH(a) +a 1 +EXPLAIN EXTENDED SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='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`.`a` AS `a`,length(`test`.`t1`.`a`) AS `LENGTH(a)` from `test`.`t1` where ((not((`test`.`t1`.`a` like 'a '))) and (`test`.`t1`.`a` = 'a')) +DROP TABLE t1; +# +# End of MDEV-8694 +# +# # MDEV-7149 Constant condition propagation erroneously applied for LIKE # CREATE TABLE t1 AS SELECT REPEAT('a',10) AS c1 LIMIT 0; diff --git a/mysql-test/t/ctype_cp1250_ch.test b/mysql-test/t/ctype_cp1250_ch.test index f5c241fb679..0bbe4cafca6 100644 --- a/mysql-test/t/ctype_cp1250_ch.test +++ b/mysql-test/t/ctype_cp1250_ch.test @@ -12,6 +12,7 @@ SHOW COLLATION LIKE 'cp1250_czech_cs'; SET @test_character_set= 'cp1250'; SET @test_collation= 'cp1250_general_ci'; -- source include/ctype_common.inc +-- source include/ctype_like_cond_propagation.inc SET @test_character_set= 'cp1250'; SET @test_collation= 'cp1250_czech_cs'; diff --git a/mysql-test/t/ctype_latin2_ch.test b/mysql-test/t/ctype_latin2_ch.test index acd93aad6d6..c8ea54e6091 100644 --- a/mysql-test/t/ctype_latin2_ch.test +++ b/mysql-test/t/ctype_latin2_ch.test @@ -33,6 +33,7 @@ drop table t1; set names latin2 collate latin2_czech_cs; --source include/ctype_pad_space.inc +--source include/ctype_like_cond_propagation.inc # We can not use ctype_filesort.inc because # order of SPACE and TAB is not strict diff --git a/mysql-test/t/ctype_tis620.test b/mysql-test/t/ctype_tis620.test index b536a00bec9..ba5db9df54f 100644 --- a/mysql-test/t/ctype_tis620.test +++ b/mysql-test/t/ctype_tis620.test @@ -157,9 +157,11 @@ SET collation_connection='tis620_thai_ci'; -- source include/ctype_filesort.inc -- source include/ctype_like_escape.inc --source include/ctype_ascii_order.inc +-- source include/ctype_like_cond_propagation.inc SET collation_connection='tis620_bin'; -- source include/ctype_filesort.inc -- source include/ctype_like_escape.inc +-- source include/ctype_like_cond_propagation.inc # End of 4.1 tests diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index d1a0c7295db..6ff95dadf15 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1614,6 +1614,38 @@ public: Item_bool_func2::get_mm_tree(param, cond_ptr) : Item_func::get_mm_tree(param, cond_ptr); } + Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond) + { + /* + LIKE differs from the regular comparison operator ('=') in the following: + - LIKE never ignores trailing spaces (even for PAD SPACE collations) + Propagation of equal fields with a PAD SPACE collation into LIKE + is not safe. + Example: + WHERE a='a ' AND a LIKE 'a' - returns true for 'a' + cannot be rewritten to: + WHERE a='a ' AND 'a ' LIKE 'a' - returns false for 'a' + Note, binary collations in MySQL/MariaDB, e.g. latin1_bin, + still have the PAD SPACE attribute and ignore trailing spaces! + - LIKE does not take into account contractions, expansions, + and ignorable characters. + Propagation of equal fields with contractions/expansions/ignorables + is also not safe. + + It's safe to propagate my_charset_bin (BINARY/VARBINARY/BLOB) values, + because they do not ignore trailing spaces and have one-to-one mapping + between a string and its weights. + The below condition should be true only for my_charset_bin + (as of version 10.1.7). + */ + uint flags= Item_func_like::compare_collation()->state; + if ((flags & MY_CS_NOPAD) && !(flags & MY_CS_NON1TO1)) + Item_args::propagate_equal_fields(thd, + Context(ANY_SUBST, + compare_collation()), + cond); + return this; + } const char *func_name() const { return "like"; } bool fix_fields(THD *thd, Item **ref); void fix_length_and_dec() diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c index 4d42973f69f..0be6ae95577 100644 --- a/strings/ctype-bin.c +++ b/strings/ctype-bin.c @@ -557,7 +557,7 @@ static MY_CHARSET_HANDLER my_charset_handler= struct charset_info_st my_charset_bin = { 63,0,0, /* number */ - MY_CS_COMPILED|MY_CS_BINSORT|MY_CS_PRIMARY,/* state */ + MY_CS_COMPILED|MY_CS_BINSORT|MY_CS_PRIMARY|MY_CS_NOPAD,/* state */ "binary", /* cs name */ "binary", /* name */ "", /* comment */ diff --git a/strings/ctype-czech.c b/strings/ctype-czech.c index 6603bc7d3e5..e3abebad91d 100644 --- a/strings/ctype-czech.c +++ b/strings/ctype-czech.c @@ -625,7 +625,8 @@ static MY_COLLATION_HANDLER my_collation_latin2_czech_ci_handler = struct charset_info_st my_charset_latin2_czech_ci = { 2,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_CSSORT|MY_CS_STRNXFRM_BAD_NWEIGHTS, /* state */ + MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_CSSORT| + MY_CS_STRNXFRM_BAD_NWEIGHTS|MY_CS_NON1TO1, /* state */ "latin2", /* cs name */ "latin2_czech_cs", /* name */ "", /* comment */ diff --git a/strings/ctype-latin1.c b/strings/ctype-latin1.c index 8bc3ac3365d..26c66d60071 100644 --- a/strings/ctype-latin1.c +++ b/strings/ctype-latin1.c @@ -736,7 +736,7 @@ static MY_COLLATION_HANDLER my_collation_german2_ci_handler= struct charset_info_st my_charset_latin1_german2_ci= { 31,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM, /* state */ + MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_NON1TO1, /* state */ "latin1", /* cs name */ "latin1_german2_ci", /* name */ "", /* comment */ diff --git a/strings/ctype-tis620.c b/strings/ctype-tis620.c index c62e58846bb..a1ca320835d 100644 --- a/strings/ctype-tis620.c +++ b/strings/ctype-tis620.c @@ -897,7 +897,7 @@ static MY_CHARSET_HANDLER my_charset_handler= struct charset_info_st my_charset_tis620_thai_ci= { 18,0,0, /* number */ - MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM, /* state */ + MY_CS_COMPILED|MY_CS_PRIMARY|MY_CS_STRNXFRM|MY_CS_NON1TO1, /* state */ "tis620", /* cs name */ "tis620_thai_ci", /* name */ "", /* comment */ diff --git a/strings/ctype-uca.c b/strings/ctype-uca.c index 60bd96e499d..b0728978e71 100644 --- a/strings/ctype-uca.c +++ b/strings/ctype-uca.c @@ -35,6 +35,8 @@ #include "strings_def.h" #include +#define MY_CS_COMMON_UCA_FLAGS (MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NON1TO1) + #define MY_UCA_CNT_FLAG_SIZE 4096 #define MY_UCA_CNT_FLAG_MASK 4095 #define MY_UCA_CNT_HEAD 1 @@ -22926,10 +22928,12 @@ MY_COLLATION_HANDLER my_collation_ucs2_uca_handler = my_propagate_complex }; +#define MY_CS_UCS2_UCA_FLAGS (MY_CS_COMMON_UCA_FLAGS|MY_CS_NONASCII) + struct charset_info_st my_charset_ucs2_unicode_ci= { 128,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_unicode_ci", /* name */ "", /* comment */ @@ -22961,7 +22965,7 @@ struct charset_info_st my_charset_ucs2_unicode_ci= struct charset_info_st my_charset_ucs2_icelandic_uca_ci= { 129,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_icelandic_ci",/* name */ "", /* comment */ @@ -22993,7 +22997,7 @@ struct charset_info_st my_charset_ucs2_icelandic_uca_ci= struct charset_info_st my_charset_ucs2_latvian_uca_ci= { 130,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_latvian_ci", /* name */ "", /* comment */ @@ -23025,7 +23029,7 @@ struct charset_info_st my_charset_ucs2_latvian_uca_ci= struct charset_info_st my_charset_ucs2_romanian_uca_ci= { 131,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_romanian_ci", /* name */ "", /* comment */ @@ -23057,7 +23061,7 @@ struct charset_info_st my_charset_ucs2_romanian_uca_ci= struct charset_info_st my_charset_ucs2_slovenian_uca_ci= { 132,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_slovenian_ci",/* name */ "", /* comment */ @@ -23089,7 +23093,7 @@ struct charset_info_st my_charset_ucs2_slovenian_uca_ci= struct charset_info_st my_charset_ucs2_polish_uca_ci= { 133,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_polish_ci", /* name */ "", /* comment */ @@ -23121,7 +23125,7 @@ struct charset_info_st my_charset_ucs2_polish_uca_ci= struct charset_info_st my_charset_ucs2_estonian_uca_ci= { 134,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_estonian_ci", /* name */ "", /* comment */ @@ -23153,7 +23157,7 @@ struct charset_info_st my_charset_ucs2_estonian_uca_ci= struct charset_info_st my_charset_ucs2_spanish_uca_ci= { 135,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_spanish_ci", /* name */ "", /* comment */ @@ -23185,7 +23189,7 @@ struct charset_info_st my_charset_ucs2_spanish_uca_ci= struct charset_info_st my_charset_ucs2_swedish_uca_ci= { 136,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_swedish_ci", /* name */ "", /* comment */ @@ -23217,7 +23221,7 @@ struct charset_info_st my_charset_ucs2_swedish_uca_ci= struct charset_info_st my_charset_ucs2_turkish_uca_ci= { 137,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_turkish_ci", /* name */ "", /* comment */ @@ -23249,7 +23253,7 @@ struct charset_info_st my_charset_ucs2_turkish_uca_ci= struct charset_info_st my_charset_ucs2_czech_uca_ci= { 138,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_czech_ci", /* name */ "", /* comment */ @@ -23282,7 +23286,7 @@ struct charset_info_st my_charset_ucs2_czech_uca_ci= struct charset_info_st my_charset_ucs2_danish_uca_ci= { 139,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_danish_ci", /* name */ "", /* comment */ @@ -23314,7 +23318,7 @@ struct charset_info_st my_charset_ucs2_danish_uca_ci= struct charset_info_st my_charset_ucs2_lithuanian_uca_ci= { 140,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_lithuanian_ci",/* name */ "", /* comment */ @@ -23346,7 +23350,7 @@ struct charset_info_st my_charset_ucs2_lithuanian_uca_ci= struct charset_info_st my_charset_ucs2_slovak_uca_ci= { 141,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_slovak_ci", /* name */ "", /* comment */ @@ -23378,7 +23382,7 @@ struct charset_info_st my_charset_ucs2_slovak_uca_ci= struct charset_info_st my_charset_ucs2_spanish2_uca_ci= { 142,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_spanish2_ci", /* name */ "", /* comment */ @@ -23411,7 +23415,7 @@ struct charset_info_st my_charset_ucs2_spanish2_uca_ci= struct charset_info_st my_charset_ucs2_roman_uca_ci= { 143,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_roman_ci", /* name */ "", /* comment */ @@ -23444,7 +23448,7 @@ struct charset_info_st my_charset_ucs2_roman_uca_ci= struct charset_info_st my_charset_ucs2_persian_uca_ci= { 144,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_persian_ci", /* name */ "", /* comment */ @@ -23477,7 +23481,7 @@ struct charset_info_st my_charset_ucs2_persian_uca_ci= struct charset_info_st my_charset_ucs2_esperanto_uca_ci= { 145,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_esperanto_ci",/* name */ "", /* comment */ @@ -23510,7 +23514,7 @@ struct charset_info_st my_charset_ucs2_esperanto_uca_ci= struct charset_info_st my_charset_ucs2_hungarian_uca_ci= { 146,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_hungarian_ci",/* name */ "", /* comment */ @@ -23542,7 +23546,7 @@ struct charset_info_st my_charset_ucs2_hungarian_uca_ci= struct charset_info_st my_charset_ucs2_sinhala_uca_ci= { 147,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* csname */ "ucs2_sinhala_ci", /* name */ "", /* comment */ @@ -23576,7 +23580,7 @@ struct charset_info_st my_charset_ucs2_sinhala_uca_ci= struct charset_info_st my_charset_ucs2_german2_uca_ci= { 148,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* csname */ "ucs2_german2_ci", /* name */ "", /* comment */ @@ -23608,7 +23612,7 @@ struct charset_info_st my_charset_ucs2_german2_uca_ci= struct charset_info_st my_charset_ucs2_croatian_mysql561_uca_ci= { 149,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_croatian_mysql561_ci", /* name */ "", /* comment */ @@ -23641,7 +23645,7 @@ struct charset_info_st my_charset_ucs2_croatian_mysql561_uca_ci= struct charset_info_st my_charset_ucs2_croatian_uca_ci= { MY_PAGE2_COLLATION_ID_UCS2,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_croatian_ci", /* name */ "", /* comment */ @@ -23674,7 +23678,7 @@ struct charset_info_st my_charset_ucs2_croatian_uca_ci= struct charset_info_st my_charset_ucs2_myanmar_uca_ci= { MY_PAGE2_COLLATION_ID_UCS2+1,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_myanmar_ci", /* name */ "", /* comment */ @@ -23707,7 +23711,7 @@ struct charset_info_st my_charset_ucs2_myanmar_uca_ci= struct charset_info_st my_charset_ucs2_unicode_520_ci= { 150,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* cs name */ "ucs2_unicode_520_ci",/* name */ "", /* comment */ @@ -23740,7 +23744,7 @@ struct charset_info_st my_charset_ucs2_unicode_520_ci= struct charset_info_st my_charset_ucs2_vietnamese_ci= { 151,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UCS2_UCA_FLAGS,/* state */ "ucs2", /* csname */ "ucs2_vietnamese_ci",/* name */ "", /* comment */ @@ -23817,7 +23821,7 @@ static uchar ctype_utf8[] = { extern MY_CHARSET_HANDLER my_charset_utf8_handler; -#define MY_CS_UTF8MB3_UCA_FLAGS (MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE) +#define MY_CS_UTF8MB3_UCA_FLAGS MY_CS_COMMON_UCA_FLAGS struct charset_info_st my_charset_utf8_unicode_ci= { @@ -24666,7 +24670,7 @@ struct charset_info_st my_charset_utf8_vietnamese_ci= extern MY_CHARSET_HANDLER my_charset_utf8mb4_handler; -#define MY_CS_UTF8MB4_UCA_FLAGS (MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_UNICODE_SUPPLEMENT) +#define MY_CS_UTF8MB4_UCA_FLAGS (MY_CS_COMMON_UCA_FLAGS|MY_CS_UNICODE_SUPPLEMENT) struct charset_info_st my_charset_utf8mb4_unicode_ci= { @@ -25529,7 +25533,7 @@ MY_COLLATION_HANDLER my_collation_utf32_uca_handler = extern MY_CHARSET_HANDLER my_charset_utf32_handler; -#define MY_CS_UTF32_UCA_FLAGS (MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII) +#define MY_CS_UTF32_UCA_FLAGS (MY_CS_COMMON_UCA_FLAGS|MY_CS_NONASCII) struct charset_info_st my_charset_utf32_unicode_ci= { @@ -26392,7 +26396,7 @@ MY_COLLATION_HANDLER my_collation_utf16_uca_handler = extern MY_CHARSET_HANDLER my_charset_utf16_handler; -#define MY_CS_UTF16_UCA_FLAGS (MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII) +#define MY_CS_UTF16_UCA_FLAGS (MY_CS_COMMON_UCA_FLAGS|MY_CS_NONASCII) struct charset_info_st my_charset_utf16_unicode_ci= { @@ -27171,7 +27175,7 @@ struct charset_info_st my_charset_utf16_myanmar_uca_ci= struct charset_info_st my_charset_utf16_unicode_520_ci= { 123,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, + MY_CS_UTF16_UCA_FLAGS,/* state */ "utf16", /* csname */ "utf16_unicode_520_ci",/* name */ "", /* comment */ diff --git a/strings/ctype-win1250ch.c b/strings/ctype-win1250ch.c index 27e6a94f67b..8e3527f9ff1 100644 --- a/strings/ctype-win1250ch.c +++ b/strings/ctype-win1250ch.c @@ -690,7 +690,8 @@ static MY_COLLATION_HANDLER my_collation_czech_ci_handler = struct charset_info_st my_charset_cp1250_czech_ci = { 34,0,0, /* number */ - MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_CSSORT|MY_CS_STRNXFRM_BAD_NWEIGHTS, /* state */ + MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_CSSORT| + MY_CS_STRNXFRM_BAD_NWEIGHTS|MY_CS_NON1TO1, /* state */ "cp1250", /* cs name */ "cp1250_czech_cs", /* name */ "", /* comment */