[MDEV-13335] UTF8 escape wildcard LIKE match has different behavior in different collations Created: 2017-07-17  Updated: 2019-04-28  Resolved: 2019-04-28

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 10.0, 10.1, 10.2, 10.3
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Su, Jun-Ming Assignee: Alexander Barkov
Resolution: Duplicate Votes: 0
Labels: upstream
Environment:

Windows 2012 R2 Server, Ubuntu LTS 16.04.2


Issue Links:
Duplicate
duplicates MDEV-17064 LIKE function has error behavior on t... Closed

 Description   

I found out there is different behavior in different collations for UTF8 escape wildcard LIKE matching.

mysql> SET collation_connection = utf8_unicode_ci;
Query OK, 0 rows affected (0.00 sec)
 
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)
 
mysql> SET collation_connection = utf8_general_ci;
Query OK, 0 rows affected (0.00 sec)
 
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)
 
mysql> SET collation_connection = utf8mb4_unicode_ci;
Query OK, 0 rows affected (0.00 sec)
 
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)
 
mysql> SET collation_connection = utf8mb4_general_ci;
Query OK, 0 rows affected (0.00 sec) 
 
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)
 
mysql> SET collation_connection = utf8mb4_unicode_520_ci;
Query OK, 0 rows affected (0.00 sec)
 
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)

I found out this problem on MySQL for a long time ago, but it says to use another collation instead, is there any ways to solve it?



 Comments   
Comment by Alice Sherepa [ 2017-07-17 ]

reproduced as described on MariaDB 10.2.7, 10.1.25, 10.3.1

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