MySQL Forums
Forum List  »  Performance

Re: Slow COUNT + GROUP BY
Posted by: Øystein Grøvlen
Date: March 23, 2015 06:04AM

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

Options: ReplyQuote


Subject
Views
Written By
Posted
1746
March 20, 2015 07:00AM
787
March 20, 2015 07:55AM
764
March 20, 2015 08:00AM
742
March 22, 2015 04:11PM
722
March 23, 2015 12:46AM
1102
March 23, 2015 02:45AM
1004
March 23, 2015 04:30AM
Re: Slow COUNT + GROUP BY
904
March 23, 2015 06:04AM
769
March 23, 2015 08:13AM
778
March 24, 2015 02:02AM
768
March 24, 2015 02:51AM
790
March 24, 2015 03:37AM


Sorry, you can't reply to this topic. It has been closed.

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.