On my WordPress site, when a user pages far back in the list of posts, the queries end up taking a couple seconds. I'd like to bring this down. Here's the query that's being executed:
SELECT SQL_CALC_FOUND_ROWS wp_posts.*
FROM wp_posts
WHERE 1=1
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
ORDER BY wp_posts.post_date DESC
LIMIT 846, 47
There are about 160k rows in the table. Here's a simplified version of the schema:
CREATE TABLE `wp_posts` (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`post_date` datetime NOT NULL default '0000-00-00 00:00:00',
`post_status` varchar(20) NOT NULL default 'publish',
`post_type` varchar(20) NOT NULL default 'post',
PRIMARY KEY (`ID`),
KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8
This is the EXPLAIN
result of the query:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE wp_posts ref type_status_date type_status_date 62 const 41519 Using where; Using filesort
Ideally, I'd like to get rid of the filesort. Any tips?