I have such a query:
SELECT va.value, vc.value
FROM votingapi_cache va
LEFT JOIN votingapi_cache vc ON vc.content_id = va.content_id
WHERE va.content_type = 'node' AND va.value_type = 'percent' AND va.tag = 'vote' AND va.function = 'average' AND vc.content_type = 'node' AND vc.tag = 'vote' AND vc.function = 'count'
ORDER BY va.value DESC, vc.value DESC LIMIT 0, 10
EXPLAIN tells me that this query uses temporary and filesort. It runs nearly 10s on table with 500k rows. How it can be optimized?
Schema:
Indexes:
After suggestions given by Joachim Isaksson, no performance improvements, EXPLAIN: