Bug #6787 LIKE not working properly with _ and utf8 data
Submitted: 24 Nov 2004 1:22 Modified: 24 Nov 2004 16:11
Reporter: Matthew Lord Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.7 OS:Any (all)
Assigned to: Alexander Barkov CPU Architecture:Any

[24 Nov 2004 1:22] Matthew Lord
Description:
LIKE "\_%" matches all rows in a table

How to repeat:
use test;

create table liketest ( name varchar(20) ) default charset=utf8;

insert into liketest values ('matt'), ('lilu'), ('_carly'), ('sidney'), ('_hoppie');

select * from liketest where name like "\_%";

Suggested fix:
Only return the correctly matching rows.
[24 Nov 2004 1:27] Matthew Lord
I was able to verify this on windows 2000 (Service Pack 4), Linux (2.4.21 #12 SMP Thu Aug 
14 00:49:40 EDT 2003 i686 i686 i386 GNU/Linux) and Solaris 9 (64 bit).

Note, this worked fine in 4.1 up until 4.1.7.  There was a late change made shortly before the 
release of 4.1.7 because a BK build that I did not too long before the release was done does
not exhibit the problem.  I also did a BK build of 4.1.8 today, 11/23, and it still has the problem.

Prepending another % sign seems to make it work correctly:
select * from liketest where name like "%\_%";
[24 Nov 2004 1:29] Matthew Lord
Another note, the results are the same whether the table is an innodb table or a myisam table.
[24 Nov 2004 16:11] Alexander Barkov
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:

fixed in 4.1.8
[29 Mar 2007 1:24] Kyle Polich
I am running version 5.0.27 and I am having this problem
[29 Mar 2007 4:01] Alexander Barkov
Kyle, I can't reproduce this proble with 5.0.x.
Can you please post a "how to repeat" instruction?
Thanks!