Bug #68814 | MySQL optimizer consider few rows to examine but it is not really obvious why | ||
---|---|---|---|
Submitted: | 29 Mar 2013 15:33 | Modified: | 23 Apr 2015 6:14 |
Reporter: | Shahriyar Rzayev | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S3 (Non-critical) |
Version: | 5.6.10 | OS: | Any (Centos 6.3) |
Assigned to: | CPU Architecture: | Any | |
Tags: | count(*) with where, Explain plan |
[29 Mar 2013 15:33]
Shahriyar Rzayev
[11 Apr 2013 8:52]
Jørgen Løland
Hi Shahriyar, The 'rows' column of EXPLAIN does not output the actual number of rows that would be read by the statement but rather an estimate. See: http://dev.mysql.com/doc/refman/5.6/en/explain-output.html#explain-output-columns That being said, the estimate is wrong. The underlying problem is within the InnoDB storage engine, which tries to balance the quality the estimates against the cost of calculating the estimate. In cases where much more than half the rows match a range, InnoDB simply assumes that #rows/2 is a good enough estimate. The difference in execution time between these queries is due to the following: 1) A different access method is chosen: index scan vs range access. 2) In the second query, the predicate "sales_id>0" has to be evaluated for 2.4 million rows. I'll transfer this bug to the InnoDB team and let them decide on the action.
[11 Apr 2013 20:12]
Shahriyar Rzayev
Thanks for reply. It is still unclear and unlogical that MySQL optimizer does not see difference beetween >0 and >1.800.000 :) I want and official reply for this issue from InnoDB team as you say.
[22 Apr 2015 15:22]
MySQL Verification Team
It seems I've also filed one for this already that I never found before reading http://mysql.az/playing-with-count-optimizer-work/ https://bugs.mysql.com/bug.php?id=73386
[23 Apr 2015 6:14]
Shahriyar Rzayev
Shane Bester, Yes, it seems to be similar. Also very interesting. Thank you for reading.