At the same time, this query detects an empty result set, and calls
return_zero_rows(), which must check the HAVING clause by:
if (having && having->val_int() == 0)
send_row=0;
However having has been already set to NULL, so return_zero_rows
doesn't check the having clause, hence the wrong result.
Solution:
There are two ways to solve this problem:
a) check join->tmp_having in addition to join->having, or
b) do not set having= 0 in JOIN::optimize.
Analysis:
Close to its end JOIN::optimize() assigns having to tmp_having, and
sets the having clause to NULL:
tmp_having= having;
if (select_options & SELECT_DESCRIBE)
{
error= 0;
DBUG_RETURN(0);
}
having= 0;
At the same time, this query detects an empty result set, and calls
return_zero_rows(), which must check the HAVING clause by:
if (having && having->val_int() == 0)
send_row=0;
However having has been already set to NULL, so return_zero_rows
doesn't check the having clause, hence the wrong result.
Solution:
There are two ways to solve this problem:
a) check join->tmp_having in addition to join->having, or
b) do not set having= 0 in JOIN::optimize.