Commit 80651436 authored by unknown's avatar unknown

Fix for LP bug#993726

Optimization of aggregate functions detected constant under max() and evalueted it, but condition in the WHWRE clause (which is always FALSE) was not taken into account
parent 213476ef
......@@ -2059,4 +2059,16 @@ MIN(a) b
0 a
DROP TABLE t1;
#
# LP bug#993726 Wrong result from a query with ALL subquery predicate in WHERE
#
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (0);
SELECT 1 FROM t1 WHERE 1 > ALL(SELECT 1 FROM t1 WHERE a!=0);
1
1
SELECT max(1) FROM t1 WHERE a!=0;
max(1)
NULL
drop table t1;
# End of 5.2 tests
......@@ -1425,4 +1425,13 @@ let $query= SELECT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b;
--echo
DROP TABLE t1;
--echo #
--echo # LP bug#993726 Wrong result from a query with ALL subquery predicate in WHERE
--echo #
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (0);
SELECT 1 FROM t1 WHERE 1 > ALL(SELECT 1 FROM t1 WHERE a!=0);
SELECT max(1) FROM t1 WHERE a!=0;
drop table t1;
--echo # End of 5.2 tests
......@@ -403,7 +403,7 @@ int opt_sum_query(THD *thd,
}
removed_tables|= table->map;
}
else if (!expr->const_item() || !is_exact_count)
else if (!expr->const_item() || !is_exact_count || conds)
{
/*
The optimization is not applicable in both cases:
......@@ -413,6 +413,8 @@ int opt_sum_query(THD *thd,
NULL if the query does not return any rows. Thus, if we are not
able to determine if the query returns any rows, we can't apply
the optimization and replace MIN/MAX with a constant.
(c) there is a WHERE clause. The WHERE conditions may result in
an empty result, but the clause cannot be taken into account here.
*/
const_result= 0;
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment