Bug #13046 LIKE pattern matching using prefix index doesn't return correct result(2)
Submitted: 7 Sep 2005 19:12 Modified: 19 Oct 2005 14:17
Reporter: Shuichi Tamagawa Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:4.1.15-bk Sep 7 / 5.0.13-bk Sep 6 OS:Windows (Windows XP / SuSE Linux)
Assigned to: Alexander Barkov CPU Architecture:Any

[7 Sep 2005 19:12] Shuichi Tamagawa
Description:
If the special characters like '_' , '%' are included within the prefix of the index, LIKE pattern matching doesn't return the correct result. If these characters are not included with in the prefix of the index, the result is fine.

This happens on both 4.1.14, 5.0.13, both MyISAM, InnoDB. Not like the bug#11650, character set doesn't matter.

How to repeat:
mysql> create table t1(c1 varchar(50) not null, index(c1(3)));
Query OK, 0 rows affected (0.13 sec)

mysql> insert into t1 values('abcdef');
Query OK, 1 row affected (0.04 sec)

mysql> insert into t1 values('_bcdef');
Query OK, 1 row affected (0.03 sec)

mysql> insert into t1 values('a_cdef');
Query OK, 1 row affected (0.04 sec)

mysql> insert into t1 values('ab_def');
Query OK, 1 row affected (0.03 sec)

mysql> insert into t1 values('abc_ef');
Query OK, 1 row affected (0.08 sec)

mysql> insert into t1 values('abcd_f');
Query OK, 1 row affected (0.13 sec)

mysql> insert into t1 values('abcde_');
Query OK, 1 row affected (0.05 sec)

mysql> select * from t1 where c1 like 'ab\_def';
Empty set (0.00 sec)
/* Should return 'ab_def' */

mysql> select * from t1 where c1 like 'ab#_def' escape '#';
Empty set (0.00 sec)
/* Should return 'ab_def' */

mysql> select * from t1 where c1 like 'abc\_ef';
+--------+
| c1     |
+--------+
| abc_ef |
+--------+
1 row in set (0.00 sec)
/* If the character '_' is not in the first three letters, the result is fine */

mysql> select * from t1 where c1 like 'abc#_ef' escape '#';
+--------+
| c1     |
+--------+
| abc_ef |
+--------+
1 row in set (0.00 sec)
/* If the character '_' is not in the first three letters, the result is fine */

Suggested fix:
N/A
[7 Sep 2005 21:14] Shuichi Tamagawa
Same results on 4.1.15-bk Sep 7
[10 Sep 2005 22:34] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/29601
[21 Sep 2005 18:14] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/30167
[7 Oct 2005 3:36] Alexander Barkov
Fixed in 4.1.15 and 5.0.15
[19 Oct 2005 14:17] Jon Stephens
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

 Documented fix in 4.1.15 and 5.0.15 changelogs.