Bug #58782 | Missing rows with SELECT .. WHERE .. IN subquery with full GROUP BY and no aggr | ||
---|---|---|---|
Submitted: | 7 Dec 2010 10:46 | Modified: | 13 Jan 2011 9:45 |
Reporter: | John Embretsen | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | bzr_WL1393 | OS: | Any |
Assigned to: | Tor Didriksen | CPU Architecture: | Any |
Tags: | wl1393 |
[7 Dec 2010 10:46]
John Embretsen
[9 Dec 2010 12:31]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/126411 3258 Tor Didriksen 2010-12-09 Bug #58782 Missing rows with SELECT .. WHERE .. IN subquery with full GROUP BY and no aggr The GROUP BY is optimized away earlier than any example queries seen so far: In JOIN::optimize() We have found that grouping can be removed since groups correspond to only one row anyway, but we still have to guarantee correct result order. The line below effectively rewrites the query from GROUP BY <fields> to ORDER BY <fields>. So, the handling of GROUP BY to disable PQ in JOIN::exec does not catch it. This is a DEPENDENT SUBQUERY, which is executed once for each outer row. This means we have to return all rows each time we do filesort, i.e. we must set limit == HA_POS_ERROR, and disable PQ. @ mysql-test/r/group_by.result New test case. @ mysql-test/r/order_by_icp_mrr.result New (correct) result. @ mysql-test/r/order_by_none.result New (correct) result. @ mysql-test/t/group_by.test New test case. @ sql/sql_select.cc If the query as a GROUP BY, then remember that fact in JOIN::prepare. Use this fact in JOIN::exec, to disable PQ. @ sql/sql_select.h Rename group to has_group_by, for readability, add had_group_by.
[10 Dec 2010 15:00]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/126532 3258 Tor Didriksen 2010-12-10 Bug #58782 Missing rows with SELECT .. WHERE .. IN subquery with full GROUP BY and no aggr The missing results were caused by a 'group by' which was transformed to an 'order by'. @ mysql-test/r/explain.result New explain result, the group by can be eliminated. @ mysql-test/r/group_by.result New test case. @ mysql-test/r/myisam_mrr.result New explain result, the group by can be eliminated. @ mysql-test/r/myisam_mrr_cost.result New explain result, the group by can be eliminated. @ mysql-test/r/myisam_mrr_cost_icp.result New explain result, the group by can be eliminated. @ mysql-test/r/myisam_mrr_icp.result New explain result, the group by can be eliminated. @ mysql-test/r/myisam_mrr_none.result New explain result, the group by can be eliminated. @ mysql-test/r/order_by_icp_mrr.result New (correct) result. @ mysql-test/r/order_by_none.result New (correct) result. @ mysql-test/t/group_by.test New test case. @ sql/sql_select.cc If the query as a GROUP BY, which can be converted to an ORDER BY, we can eliminate it for subqueries.