Re: Slow COUNT + GROUP BY
Hi,
The only explanation I can think of for why a scan using the primary key is quicker than using the index, is that the PRIMARY key is to a larger degree cached in memory than what is the case for the index on day column. Do the queries show the same timing behavior if you repeat them a few times?
I also see that the PRIMARY KEY contains all columns of the table. That means that any secondary index will be as large as the primary key index (i.e., the whole table). Still, it should be cheaper to scan a part of the index instead of the whole table expect when the index range scan requires more I/O. For more efficient secondary indexes you may consider using an artificial primary key (e.g., an AUTO_INCREMENT column). Then the day index will be much smaller.
Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway
Subject
Views
Written By
Posted
1911
March 20, 2015 07:00AM
871
March 20, 2015 07:55AM
844
March 20, 2015 08:00AM
890
March 22, 2015 04:11PM
799
March 23, 2015 12:46AM
1179
March 23, 2015 02:45AM
1137
March 23, 2015 04:30AM
Re: Slow COUNT + GROUP BY
995
March 23, 2015 06:04AM
868
March 23, 2015 08:13AM
861
March 24, 2015 02:02AM
859
March 24, 2015 02:51AM
873
March 24, 2015 03:37AM
Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.