سؤال

We currently have a query in our app like this:

SELECT * FROM combos WHERE text = '[text]'

We're putting a category_id column on combos, and the query will change to this:

SELECT * FROM combos WHERE category_id in ([c1],[c2],[...]) AND text = '[text]'

At the moment, there's an index on combos(text). We're thinking of removing it and putting one on combos(category_id, text). Will MYSQL be able to use the new index like it did the old one? If the answer is 'it depends', what does it depend on? Should we keep the old one in case it can't?

هل كانت مفيدة؟

المحلول

sometimes....as long as there is no range condition:

http://dev.mysql.com/doc/refman/5.5/en/index-merge-optimization.html

you might be better of with (text, category_id) -- depending on your data distribution!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top