sql - Optimizing aggregation on MySQL Table with 850 million rows -


i have query i'm using summarize via aggregations.

the table called 'connections' , has 843 million rows.

create table `connections` (   `app_id` varchar(16) default null,   `user_id` bigint(20) default null,   `time_started_dt` datetime default null,   `device` varchar(255) default null,   `os` varchar(255) default null,   `firmware` varchar(255) default null,   key `app_id` (`bid`),   key `time_started_dt` (`time_started_dt`) ) engine=innodb default charset=utf8; 

when try run query, such 1 below, takes on 10 hours , end killing it. see mistakes i'm making, of have suggestions how optimize query?

select app_id, max(time_started_dt), min(time_started_dt), count(*) connections group app_id 

i suggest create composite index on (app_id, time_started_dt):

alter table connections add index(app_id, time_started_dt) 

Comments