I recently discovered how to benefit from the information EXPLAIN provides for SQL and I figured I should run all my queries through an EXPLAIN clause to see if I have unoptimized stuff. Turns out I have and I don't know what to do about it..
If I EXPLAIN this query
SELECT `id`,`username`,`first_name`,`last_name`
FROM `users`
WHERE (`username` LIKE '%kelon%'
OR `email` LIKE '%kelon%'
OR `first_name` LIKE '%kelon%'
OR `last_name` LIKE '%kelon%'
OR `facebook` LIKE '%kelon%'
OR `twitter` LIKE '%kelon%'
OR `skype` LIKE '%kelon%')
I get ALL
for type
, which is obviously the worst scenario, and I get NULL
for possible_keys
even though I have indexes on all of the columns. How can I optimize this messy query so that mysql wouldn't run away in case of a few million records?