0

MySql does not use index on LIKE if wildcards are on both start and end.

Is there a work around for this query so it will use index:

SELECT * FROM Company WHERE Name LIKE '%ad%'
john
  • 93
  • 9
  • possible duplicate of [Optimization of MySQL search using "like" and wildcards](http://stackoverflow.com/questions/2081998/optimization-of-mysql-search-using-like-and-wildcards) – Daniel A. White Jun 21 '13 at 12:19
  • possible duplicate of [Mysql Improve Search Performance with wildcards (%%)](http://stackoverflow.com/questions/5905125/mysql-improve-search-performance-with-wildcards) – Evan Mulawski Jun 21 '13 at 12:20
  • Read my presentation [Full Text Search Throwdown](http://www.slideshare.net/billkarwin/practical-full-text-search-with-my-sql). – Bill Karwin Jun 21 '13 at 12:53

2 Answers2

2

Maybe use fulltext search for such things: http://dev.mysql.com/doc/refman/5.6/en/fulltext-search.html

Adrian
  • 2,233
  • 1
  • 22
  • 33
0

Simple, don't use index at the start of the LIKE expression.

Adjust your data accordingly - use extra columns if you have to.

vikingsteve
  • 38,481
  • 23
  • 112
  • 156
  • Thanks! But I need to have it on both start and end. I also have tons of data. Well I think there is no way to speed this search. – john Jun 21 '13 at 12:20
  • 1
    Correct, it's not possible, unless you can find a way to split your data into a new column and search on that. – vikingsteve Jun 21 '13 at 12:26