mysql - Select from a big table with GROUP BY and ORDER BY -
i need top 30 ips period (month here) maximum sum of bytes.
select sum(bytes) bytes, ip table stamp_inserted >= '2015-04-01 00:00:00' group ip order bytes desc limit 30
table has 10 000 000+ records (will grow). type myisam.
i tryed add indexes bytes, ip, stamp_insered. , 1 index (complex index?).
explain says:
type: range key: stamp_inserted (complex index) rows: 6988465 extra: using where; using index; using temporary; using filesort
it takes 15 seconds. if remove order - 10 seconds. normal? or how can make faster?
table structure:
create table if not exists `all` ( `id` int(10) unsigned not null auto_increment, `ip` char(15) not null, `bytes` bigint(20) unsigned not null, `stamp_inserted` datetime not null, primary key (`id`), key `ip` (`ip_dst`), key `bytes` (`bytes`), key `stamp_inserted` (`stamp_inserted`), key `bytes_2` (`bytes`,`ip`,`stamp_inserted`) ) engine=myisam default charset=utf8 auto_increment=11218827 ;
Comments
Post a Comment