I'm having trouble getting a decent query time from a large MySQL table, it currently takes more than 20 seconds. The problem is GROUP BY, since MySQL has to run the file port, but I don't see how I can get around this.
QUERY
SELECT play_date, COUNT(DISTINCT(email)) AS count FROM log WHERE type = 'play' AND play_date BETWEEN '2009-02-23' AND '2009-02-24' GROUP BY play_date ORDER BY play_date desc
EXPLAIN
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE log ALL type,type_2 NULL NULL NULL 530892 Using where; Using filesort
TABLE STRUCTURE
CREATE TABLE IF NOT EXISTS `log` ( `id` int(11) NOT NULL auto_increment, `email` varchar(255) NOT NULL, `type` enum('played','reg','friend') NOT NULL, `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, `play_date` date NOT NULL, `email_refer` varchar(255) NOT NULL, `remote_addr` varchar(15) NOT NULL, PRIMARY KEY (`id`), KEY `email` (`email`), KEY `type` (`type`), KEY `email_refer` (`email_refer`), KEY `type_2` (`type`,`timestamp`,`play_date`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=707859 ;
If someone knows how I could improve speed, I would be very grateful
Tom
EDIT
I added a new index using only play_date and enter, but MySQL refuses to use it
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE log ALL play_date NULL NULL NULL 801647 Using where; Using filesort
This index was created using ALTER TABLE log ADD INDEX ( type , play_date );