mirror of
https://github.com/MariaDB/server.git
synced 2026-05-09 16:44:29 +02:00
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. These parts may be lost during further having condition transformation in JOIN::exec. The fix is adding 'having' condition check for const tables after make_join_statistics is performed. mysql-test/r/having.result: test case mysql-test/t/having.test: test result sql/sql_select.cc: added 'having' condition check for const tables after make_join_statistics is performed.
This commit is contained in:
parent
a76b8f9a1d
commit
ad6e00e3b2
3 changed files with 90 additions and 0 deletions
|
|
@ -1112,6 +1112,31 @@ JOIN::optimize()
|
|||
{
|
||||
conds=new Item_int((longlong) 0,1); // Always false
|
||||
}
|
||||
|
||||
/*
|
||||
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).
|
||||
This check is performed only for those conditions
|
||||
which do not use aggregate functions. In such case
|
||||
temporary table may not be used and const condition
|
||||
elements may be lost during further having
|
||||
condition transformation in JOIN::exec.
|
||||
*/
|
||||
if (having && !having->with_sum_func)
|
||||
{
|
||||
COND *const_cond= make_cond_for_table(having, const_table_map, 0);
|
||||
DBUG_EXECUTE("where", print_where(const_cond, "const_having_cond",
|
||||
QT_ORDINARY););
|
||||
if (const_cond && !const_cond->val_int())
|
||||
{
|
||||
zero_result_cause= "Impossible HAVING noticed after reading const tables";
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (make_join_select(this, select, conds))
|
||||
{
|
||||
zero_result_cause=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue