[MDEV-17064] LIKE function has error behavior on the fields in which the collation is xxx_unicode_xx Created: 2018-08-24  Updated: 2019-04-28  Resolved: 2018-10-15

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 10.0, 10.1, 10.3.9, 10.2, 10.3
Fix Version/s: 10.0.37, 10.3.11, 10.4.0, 10.1.37, 10.2.19

Type: Bug Priority: Major
Reporter: Tao Su Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows Plateform


Issue Links:
Duplicate
is duplicated by MDEV-13335 UTF8 escape wildcard LIKE match has d... Closed

 Description   

MariaDB [(none)]> use test;
Database changed
 
MariaDB [test]> create table like_test(name varchar(20) character set 'utf8' collate 'utf8_unicode_ci');
Query OK, 0 rows affected (0.012 sec)
 
MariaDB [test]> insert into like_test values('radio! test');
Query OK, 1 row affected (0.003 sec)
 
MariaDB [test]> select * from like_test where name like '%!!%' escape '!';
Empty set (0.002 sec) -- this is wrong!
 
MariaDB [test]> ALTER TABLE like_test CHANGE COLUMN name name VARCHAR(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
Query OK, 1 row affected (0.032 sec)
Records: 1  Duplicates: 0  Warnings: 0
 
MariaDB [test]> select * from like_test where name like '%!!%' escape '!';
+-------------+
| name        |
+-------------+
| radio! test |
+-------------+
1 row in set (0.001 sec)

I still get empty set when I alter the collation of the field "name" to utf8_unicode_520_ci, utf8mb4_unicode_ci, utf8mb4_unicode_520_ci. But all work fine on utf8_general_ci, utf8mb4_general_ci.

Pls forgive me for my bad english.



 Comments   
Comment by Alice Sherepa [ 2018-08-28 ]

Thanks for the report!
Reproduced as described on MariaDB 10.0-10.3
not repeatable in MySQL 8.0.11

mysql> show create table like_test;
+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table     | Create Table                                                                                                                                                               |
+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| like_test | CREATE TABLE `like_test` (
  `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
mysql> select * from like_test where name like '%!!%' escape '!';
+-------------+
| name        |
+-------------+
| radio! test |
+-------------+
1 row in set (0.00 sec)
 
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.11    |
+-----------+
1 row in set (0.00 sec)

MariaDB 10.2

MariaDB [test]> create or replace table t1(name varchar(20) character set 'utf8' collate 'utf8_unicode_ci') ;
Query OK, 0 rows affected (0.07 sec)
 
MariaDB [test]> insert into t1 values('radio! test');
Query OK, 1 row affected (0.01 sec)
 
MariaDB [test]> select * from t1 where name like '%!!%' escape '!';
Empty set (0.00 sec)
 
MariaDB [test]> select * from t1 where name like '%!!!%' escape '!';
+-------------+
| name        |
+-------------+
| radio! test |
+-------------+
1 row in set (0.00 sec)
 
MariaDB [test]> ALTER TABLE t1 CHANGE COLUMN name name VARCHAR(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
Query OK, 1 row affected (0.10 sec)                
Records: 1  Duplicates: 0  Warnings: 0
 
MariaDB [test]> select * from t1 where name like '%!!%' escape '!';
+-------------+
| name        |
+-------------+
| radio! test |
+-------------+
1 row in set (0.00 sec)

Comment by Alexander Barkov [ 2018-10-15 ]

A smaller script reproducing the problem:

CREATE OR REPLACE TABLE t1 (name VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci);
INSERT INTO t1 VALUES ('radio! test');
SELECT name LIKE '%!!%' ESCAPE '!' AS c1,
       name LIKE '%!!%' COLLATE utf8_general_ci ESCAPE '!' AS c2
FROM t1;

+------+------+
| c1   | c2   |
+------+------+
|    0 |    1 |
+------+------+

Comment by Alexander Barkov [ 2018-10-15 ]

A similar bug was earlier fixed in MySQL in utf8_general_ci:
https://bugs.mysql.com/bug.php?id=11754

Generated at Thu Feb 08 08:33:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.