mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fix for BUG#20954: avg(keyval) retuns 0.38 but max(keyval) returns an empty set
The problem was in that opt_sum_query() replaced MIN/MAX functions with the corresponding constant found in a key, but due to imprecise representation of float numbers, when evaluating the where clause, this comparison failed. When MIN/MAX optimization detects that all tables can be removed, also remove all conjuncts in a where clause that refer to these tables. As a result of this fix, these conditions are not evaluated twice, and in the case of float number comparisons we do not discard result rows due to imprecise float representation. As a side-effect this fix also corrects an unnoticed problem in bug 12882.
This commit is contained in:
@ -547,6 +547,24 @@ JOIN::optimize()
|
||||
}
|
||||
zero_result_cause= "Select tables optimized away";
|
||||
tables_list= 0; // All tables resolved
|
||||
/*
|
||||
Extract all table-independent conditions and replace the WHERE
|
||||
clause with them. All other conditions were computed by opt_sum_query
|
||||
and the MIN/MAX/COUNT function(s) have been replaced by constants,
|
||||
so there is no need to compute the whole WHERE clause again.
|
||||
Notice that make_cond_for_table() will always succeed to remove all
|
||||
computed conditions, because opt_sum_query() is applicable only to
|
||||
conjunctions.
|
||||
*/
|
||||
if (conds)
|
||||
{
|
||||
COND *table_independent_conds=
|
||||
make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0);
|
||||
DBUG_EXECUTE("where",
|
||||
print_where(table_independent_conds,
|
||||
"where after opt_sum_query()"););
|
||||
conds= table_independent_conds;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!tables_list)
|
||||
|
Reference in New Issue
Block a user