I am trying to improve the performance of a hammered wordpress DB by adding indexes to queries that appear in the slow query log.
In MS SQL you can use query hints to force a query to use an index but it is usually quite easy to get a query to use an index if you cover the columns correctly etc.
I have this query that appears in the slow query log a lot
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish')
ORDER BY wp_posts.post_date DESC
LIMIT 18310, 5;
I created a covering unique index on wp_posts
on post_date, post_status, post_type and post_id
and restarted MySQL however when I run explain the index used is
status_password_id
and in the possible keys my new index doesn't even appear although it's a covering index e.g I just get
type_status_date,status_password_id
Therefore neither the used index or the possible choices the "optimiser" if MySQL has one is even considering my index which has post_date as the first column. I would have thought a query that is basically doing a TOP and ordering by date with
ORDER BY wp_posts.post_date DESC LIMIT 18310, 5;
Would want to use an index sorted by date for speed, especially one that had all the other fields required to satisfy the query in it as well?
Does MySQL have query hints to force an index to be used for speed/performance tests or is there something else I need to do to see why this index is being ignored.
I would love it if Navicat had a Visual Query Execution Plan like MS SQL but it seems EXPLAIN is the best it has to offer.
Anyone with any hints on how I can either force the index to be used or work out why its being ignored would be very helpful!
Thanks