Pergunta

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?

Foi útil?

Solução

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!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top