Table structure:
CREATE TABLE IF NOT EXISTS `logs` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `user` bigint(20) unsigned NOT NULL, `type` tinyint(1) unsigned NOT NULL, `date` int(11) unsigned NOT NULL, `plus` decimal(10,2) unsigned NOT NULL, `minus` decimal(10,2) unsigned NOT NULL, `tax` decimal(10,2) unsigned NOT NULL, `item` bigint(20) unsigned NOT NULL, `info` char(10) NOT NULL, PRIMARY KEY (`id`), KEY `item` (`item`), KEY `user` (`user`), KEY `type` (`type`), KEY `date` (`date`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 PACK_KEYS=0 ROW_FORMAT=FIXED;
Query:
SELECT logs.item, COUNT(logs.item) AS total FROM logs WHERE logs.type = 4 GROUP BY logs.item;
The table stores 110 thousand records, of which 50 thousand records are of type 4. Execution time: 0.13 seconds
I know this is fast, but can I do it faster?
I expect 1 million records, and thus, time will grow quite a bit.
source share