Bug #48044 | MySQL processing HAVING clauses incorrectly without DISTINCT clause | ||
---|---|---|---|
Submitted: | 14 Oct 2009 15:13 | Modified: | 1 Mar 2010 10:18 |
Reporter: | Patrick Crews | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.0,5.1,6.0 | OS: | Any |
Assigned to: | Assigned Account | CPU Architecture: | Any |
Tags: | distinct, having, regression |
[14 Oct 2009 15:13]
Patrick Crews
[14 Oct 2009 20:06]
Patrick Crews
NOTE: The join_cache_level and engine_condition_pushdown values should both be 1. However, these variables do not affect the result sets of the test.
[19 Oct 2009 15:00]
Patrick Crews
EXPLAIN output: Query 1: EXPLAIN SELECT `time_key` field1 FROM CC HAVING ( 2 , 5 ) IN ( SELECT 6 , 8 ) AND field1 ORDER BY field1 ; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY CC index NULL time_key 4 NULL 20 Using index 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING Query 2: EXPLAIN SELECT DISTINCT `time_key` field1 FROM CC HAVING ( 2 , 5 ) IN ( SELECT 6 , 8 ) AND field1 ORDER BY field1 /* TRANSFORM_OUTCOME_DISTINCT */ ; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY CC range NULL time_key 4 NULL 7 Using index for group-by 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible HAVING
[23 Nov 2009 12:00]
Manyi Lu
Title changed since this bug is not 6.0-specific, it exists in all versions.
[1 Mar 2010 10:15]
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/101828 3344 Sergey Glukhov 2010-03-01 Bug#51242 HAVING clause on table join produce incorrect results The problem is that when we make conditon for grouped result const part of condition is cut off. It happens because some parts of 'having' condition which refer to outer join become const after make_join_statistics. The fix is adding 'having' condition check for 'having' const tables after make_join_statistics is performed. Note: This patch also fixes problems described in Bug#48916, Bug #48044, Bug#48118. @ mysql-test/r/having.result test result @ mysql-test/t/having.test test case @ sql/sql_select.cc It's necessary to check const part of HAVING cond as there is a chance that some cond parts may become const items after make_join_statisctics(for example when Item is a reference to cost table field from outer join).
[1 Mar 2010 10:18]
Sergei Glukhov
This problems is fixed in Bug#51242, closed as duplicate
[1 Mar 2010 14:05]
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/101874 3344 Sergey Glukhov 2010-03-01 Bug#51242 HAVING clause on table join produce incorrect results The problem is that when we make conditon for grouped result const part of condition is cut off. It happens because some parts of 'having' condition which refer to outer join become const after make_join_statistics. The fix is adding 'having' condition check for 'having' const tables after make_join_statistics is performed. Note: This patch also fixes problems described in Bug#48916, Bug #48044, Bug#48118. @ mysql-test/r/having.result test result @ mysql-test/t/having.test test case @ sql/sql_select.cc It's necessary to check const part of HAVING cond as there is a chance that some cond parts may become const items after make_join_statisctics(for example when Item is a reference to cost table field from outer join).
[10 Mar 2010 12:43]
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/102877 3385 Sergey Glukhov 2010-03-10 Bug#51242 HAVING clause on table join produce incorrect results The problem is that when we make conditon for grouped result const part of condition is cut off. It happens because some parts of 'having' condition which refer to outer join become const after make_join_statistics. The fix is adding 'having' condition check for 'having' const tables after make_join_statistics is performed. Note: This patch also fixes problems described in Bug#48916, Bug #48044, Bug#48118. @ mysql-test/r/having.result test result @ mysql-test/t/having.test test case @ sql/sql_select.cc It's necessary to check const part of HAVING cond as there is a chance that some cond parts may become const items after make_join_statisctics(for example when Item is a reference to const table field from outer join). Note: This is applicable only for those conditions which do not use aggregate fucntions.
[5 Apr 2010 12:47]
Sergei Glukhov
Correction: duplicated with Bug#48916