Bug #38213 | MySQL does not seem to execute select count (distinct) efficiently | ||
---|---|---|---|
Submitted: | 17 Jul 2008 20:46 | Modified: | 7 Apr 2010 14:54 |
Reporter: | Zardosht Kasheff (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.1.23-rc | OS: | Any |
Assigned to: | Georgi Kodinov | CPU Architecture: | Any |
[17 Jul 2008 20:46]
Zardosht Kasheff
[18 Jul 2008 3:59]
Valeriy Kravchuk
Thank you for a problem report. It sounds like a reasonable feature request to apply a loose index scan in case of count(distinct ...). See http://dev.mysql.com/doc/refman/5.1/en/loose-index-scan.html. Please, check.
[18 Jul 2008 14:30]
Zardosht Kasheff
I guess the main point is that select count (distinct) should perform just as efficiently as select distinct. Right now, select distinct is much more efficient. I could not quite tell from the link of select distinct is done with a loose index scan, but if so, then yes, that is what I am proposing.
[18 Jul 2008 20:05]
Valeriy Kravchuk
I'd also like to request additional comment in EXPLAIN/EXPLAIN EXTENDED when/if loose index scan is used.
[7 Apr 2010 10:58]
Georgi Kodinov
WL3220 that implements this is pushed to 5.5
[7 Apr 2010 14:54]
Paul DuBois
Noted in 5.5.0 changelog. SELECT COUNT(DISTINCT) was slow compared with SELECT DISTINCT. Now the server can use loose index scan for certain forms of aggregate functions that use DISTINCT. See http://dev.mysql.com/doc/refman/5.5/en/loose-index-scan.html