Here is my query:
SELECT name, usage_guidance, total_used_num
FROM tags
WHERE
( name LIKE CONCAT('%', ?, '%') OR
usage_guidance LIKE CONCAT(?, '%') )
AND name NOT IN ($in)
ORDER BY name LIKE CONCAT('%', ?, '%') DESC, name ASC
LIMIT 6
Which one is the best index?
tags(name,usage_guidance)
tags(usage_guidance,name)
tags(name)
tags(usage_guidance)
Or is there any better option?! You know, when LIKE
comes in, I'm getting confused bout creating indexes. Because LIKE %something
would never take any benefit of indexes. Also in query above I have both AND
, OR
and IN
.. That's why I asked this question to know your opinion about it too.
Here is my table structure:
CREATE TABLE `tags` (
`id` int(11) NOT NULL,
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`usage_guidance` varchar(150) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`parent_id` int(11) UNSIGNED DEFAULT NULL,
`related` int(11) UNSIGNED DEFAULT NULL,
`total_used_num` int(11) UNSIGNED NOT NULL,
`date_time` int(11) UNSIGNED NOT NULL
)
ENGINE=InnoDB DEFAULT CHARSET=latin1;
And I'm trying to make a autocomplete suggestion query. Something like this: