-- Why would this (sub)query do a filesort? It's already got an index on activity_reviewid! --- First query: EXPLAIN SELECT a.activity_reviewid ,MIN(a.activity_startsecs) startsecs , MAX(a.activity_startsecs + a.activity_durationsecs) endsecs ,SUM(a.activity_durationsecs) totalsecs ,SUM(IF((a.activity_code)=('R'),a.activity_durationsecs,0)) reviewersecs ,SUM(IF((a.activity_code)=('A'),a.activity_durationsecs,0)) authorsecs FROM activity a GROUP BY a.activity_reviewid ; +----+-------------+-------+------+---------------+------+---------+------+-------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+-------+---------------------------------+ | 1 | SIMPLE | a | ALL | NULL | NULL | NULL | NULL | 21453 | Using temporary; Using filesort | +----+-------------+-------+------+---------------+------+---------+------+-------+---------------------------------+ CREATE TABLE `activity` ( `activity_id` int(11) NOT NULL AUTO_INCREMENT, `activity_startdate` datetime NOT NULL, `activity_durationsecs` int(10) unsigned NOT NULL, `activity_userid` int(11) NOT NULL, `activity_reviewid` int(11) NOT NULL, `activity_code` char(1) NOT NULL, `activity_startsecs` int(10) unsigned NOT NULL, PRIMARY KEY (`activity_id`), KEY `idx_activity_reviewId` (`activity_reviewid`), KEY `idx_activity_startdate` (`activity_startdate`), KEY `idx_activity_userId_startDate` (`activity_userid`,`activity_startdate`), KEY `idx_activity_userId_reviewId` (`activity_userid`,`activity_reviewid`) ) ENGINE=MyISAM AUTO_INCREMENT=21472 DEFAULT CHARSET=utf8