i have a table:
CREATE TABLE `p` (
`id` bigint(20) unsigned NOT NULL,
`rtime` datetime NOT NULL,
`d` int(10) NOT NULL,
`n` int(10) NOT NULL,
PRIMARY KEY (`rtime`,`id`,`d`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
and i have a query:
select id, d, sum(n) from p where rtime between '2012-08-25' and date(now()) group by id, d;
i'm running explain on this query on a tiny table (2 records) and it tells me it's going to use my PK:
id | select_type | table | type | possible_keys key | key | key_len | ref | rows | Extra
1 | SIMPLE | p | range | PRIMARY | PRIMARY | 8 | NULL | 1 | Using where; Using temporary; Using filesort
but when i use the same query on the same table - only this time it's huge (350 million records) - it prefers to go through all the records and ignore my keys
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
1 | SIMPLE | p | ALL | PRIMARY | NULL | NULL | NULL | 355465280 | Using where; Using temporary; Using filesort
obviously, this is extremely slow.. can anyone help?
EDIT: this simple query is also taking a significant amount of time:
select count(*) from propagation_delay where rtime > '2012-08-28';