I have a query like this:
SELECT *
FROM `rss_item`
WHERE `feed_id` = 1 and `timestamp` < 1350698635
ORDER BY `rss_item`.`timestamp` ASC
MySQL: 5.1; table engine: innodb
Explain result:
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
1 | SIMPLE | rss_item | range | timestamp | timestamp | 4 | NULL | 133534 | Using where
Table schema:
CREATE TABLE `rss_item2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(1000) NOT NULL,
`description` longtext NOT NULL,
`url` varchar(200) NOT NULL,
`url_crc` bigint(20) NOT NULL,
`date` datetime NOT NULL,
`timestamp` int(11) NOT NULL,
`feed_id` int(11) NOT NULL,
`image` varchar(250) NOT NULL,
`goto` int(11) NOT NULL,
`likes` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `timestamp` (`timestamp`,`feed_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2425930 DEFAULT CHARSET=utf8
This query with 400,000 rows takes 4 seconds. I added a composite index on feed_id
and timestamp
fields. How can I tune this query?