Bug #48916 | Server incorrectly processing HAVING clauses with an ORDER BY clause | ||
---|---|---|---|
Submitted: | 19 Nov 2009 17:12 | Modified: | 22 Apr 2011 13:31 |
Reporter: | Patrick Crews | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.0+ | OS: | Any |
Assigned to: | Sergei Glukhov | CPU Architecture: | Any |
Tags: | having |
[19 Nov 2009 17:12]
Patrick Crews
[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.
[16 Jun 2010 6:53]
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/111209 3432 Sergey Glukhov 2010-06-16 Bug#48916 Server incorrectly processing HAVING clauses with an ORDER BY clause Before sorting HAVING condition is splitted into two parts, first past is a table related condition and the rest of is HAVING part. Extraction of HAVING part does not take into account the fact that some of conditions might be non-const but have 'used_tables' equal to zero(particulary IN subselect) and because of that these conditions are cut off by make_cond_for_table() function. The fix is to split extraction of HAVING part into two steps: 1. extract condition which does not belong to the sorted table 2. extract condition which has 'used_tables' equal to zero and depending on result use one or union of them. @ mysql-test/r/having.result test case @ mysql-test/t/having.test test case @ sql/sql_select.cc The fix is to split extraction of HAVING part into two steps: 1. extract condition which does not belong to sorted table 2. extract condition which has 'used_tables' equal to zero and depending on result use one or union of them.
[22 Jun 2010 1:56]
Igor Babaev
Gluh, With a proper patch for bug #52336 this bug #48916 will be fixed as well. A proper fix for bug #52336 could look like the one accepted in the code of MariaDB 5.1.47: - Item* sort_table_cond= make_cond_for_table(curr_join->tmp_having, - used_tables, - used_tables); + Item* sort_table_cond= make_cond_for_table(curr_join->tmp_having, + used_tables, + (table_map) 0); Please, reconsider the fix for bug ##52336. Regards, Igor.
[10 Dec 2010 12:16]
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/126520 3515 Sergey Glukhov 2010-12-10 Bug#48916 Server incorrectly processing HAVING clauses with an ORDER BY clause Before sorting HAVING condition is splitted into two parts, first past is a table related condition and the rest of is HAVING part. Extraction of HAVING part does not take into account the fact that some of conditions might be non-const but have 'used_tables' == 0 (undependent subqueries) and because of that these conditions are cut off by make_cond_for_table() function. The fix is to use (table_map) 0 instead of used_tables in third argument for make_cond_for_table() function. It allows to extract elements which belong to sorted table and in addition elements which are undependend subqueries. @ mysql-test/r/having.result test case @ mysql-test/t/having.test test case @ sql/sql_select.cc The fix is to use (table_map) 0 instead of used_tables in third argument for make_cond_for_table() function. It allows to extract elements which belong to sorted table and in addition elements which are undependend subqueries.
[30 Dec 2010 11: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/127710 3537 Sergey Glukhov 2010-12-30 Bug#48916 Server incorrectly processing HAVING clauses with an ORDER BY clause Before sorting HAVING condition is split into two parts, first part is a table related condition and the rest of is HAVING part. Extraction of HAVING part does not take into account the fact that some of conditions might be non-const but have 'used_tables' == 0 (undependent subqueries) and because of that these conditions are cut off by make_cond_for_table() function. The fix is to use (table_map) 0 instead of used_tables in third argument for make_cond_for_table() function. It allows to extract elements which belong to sorted table and in addition elements which are undependend subqueries. @ mysql-test/r/having.result test result @ mysql-test/t/having.test test case @ sql/sql_select.cc The fix is to use (table_map) 0 instead of used_tables in third argument for make_cond_for_table() function. It allows to extract elements which belong to sorted table and in addition elements which are undependend subqueries.
[22 Apr 2011 13:31]
Paul DuBois
Noted in 5.1.58, 5.5.13, 5.6.3 changelogs. The optimizer sometimes incorrectly processed HAVING clauses for queries that did not also have an ORDER BY clause. CHANGESET - http://lists.mysql.com/commits/135944