log-queries-not-using-indexes and LIKE in MySQL
I have this "log-queries-not-using-indexes" enabled in MySQL. I have one query which is being logged by MySQL as such i.e. query that is not using ind开发者_开发知识库exes. The thing is this query uses LIKE for e.g.
category like '%fashion%'
and if I remove LIKE or change it to
category = 'fashion'
then it says it is using indexes.
So when we are using LIKE in our query, MySQL will log it as not using indexes no matter what?
Thanks
Using a clause like %fashion%
will never use a regular index. You need a full-text index if you want to do that kind of search.
Remember that a varchar
indexes on first part of the string. So, if you are searching for an ocurrence of fashion
on any part of the string, then index will offer no help to improve performance since you will need to search every single string.
However, if you only search for the first part like this:
select * from table where field like 'fashion%'
Then index could be used and could be helpful.
精彩评论