diff options
author | unknown <sanja@montyprogram.com> | 2012-05-07 13:26:34 +0300 |
---|---|---|
committer | unknown <sanja@montyprogram.com> | 2012-05-07 13:26:34 +0300 |
commit | 8065143637dd622b094e548ae373a28bbe78e028 (patch) | |
tree | efb9a9e1b50aee07acb2f2909bfb266fc26ba7a4 | |
parent | 213476ef3e2649c928c65705c08176282afbb55b (diff) | |
download | mariadb-git-8065143637dd622b094e548ae373a28bbe78e028.tar.gz |
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
-rw-r--r-- | mysql-test/r/group_by.result | 12 | ||||
-rw-r--r-- | mysql-test/t/group_by.test | 9 | ||||
-rw-r--r-- | sql/opt_sum.cc | 4 |
3 files changed, 24 insertions, 1 deletions
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 609604c2d66..ad4fc2b98bb 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -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 diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 7fd7aaccfdf..34bab173985 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -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 diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 92a286a3b1c..35986cf7fc0 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -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; |