summaryrefslogtreecommitdiff
path: root/mysql-test/t/func_group.test
diff options
context:
space:
mode:
authorunknown <timour@mysql.com>2005-09-21 09:49:19 +0300
committerunknown <timour@mysql.com>2005-09-21 09:49:19 +0300
commit8e7217e43bed6db3bffd97a39b85c65e1a72579a (patch)
treedb20d5fda8d7bf84477295d248851e18371614eb /mysql-test/t/func_group.test
parente6f860aad0fd3f831dc6db9ecb94fbf71f3b9ed9 (diff)
downloadmariadb-git-8e7217e43bed6db3bffd97a39b85c65e1a72579a.tar.gz
Fix for BUG#12882 - min/max inconsistent on empty table.
The problem was in that the MIN/MAX optimization in opt_sum_query was replacing MIN/MAX functions with their constant argument without taking into account that a query has no result rows. mysql-test/r/func_group.result: Test for BUG#12882. mysql-test/t/func_group.test: Test for BUG#12882. sql/item_sum.cc: If it is known that a query has no result rows, do not call add() via the call to Item_sum::no_rows_in_result() which calls reset(). Instead directly call clear() so that the MIN and MAX functions produce NULL when there are no result rows. sql/opt_sum.cc: * Do not apply MIN/MAX optimization when the operand of MIN/MAX is a constant if it can't be determined whether the query has any result rows. The reason is that if the query has result rows, then the result of MIN/MAX is its constant argument, but if the query result is empty, then the result of MIN/MAX must be NULL irrespective of its argument. * The patch also simplifies a bit the branch that hadles COUNT().
Diffstat (limited to 'mysql-test/t/func_group.test')
-rw-r--r--mysql-test/t/func_group.test69
1 files changed, 69 insertions, 0 deletions
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index 4dc8d66c4f1..f833f482f73 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -527,4 +527,73 @@ INSERT INTO t1 VALUES
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
DROP TABLE t1;
+#
+# Bug #12882 min/max inconsistent on empty table
+#
+
+create table t1m (a int) engine=myisam;
+create table t1i (a int) engine=innodb;
+create table t2m (a int) engine=myisam;
+create table t2i (a int) engine=innodb;
+insert into t2m values (5);
+insert into t2i values (5);
+
+# test with MyISAM
+select min(a) from t1m;
+select min(7) from t1m;
+select min(7) from DUAL;
+explain select min(7) from t2m join t1m;
+select min(7) from t2m join t1m;
+
+select max(a) from t1m;
+select max(7) from t1m;
+select max(7) from DUAL;
+explain select max(7) from t2m join t1m;
+select max(7) from t2m join t1m;
+
+select 1, min(a) from t1m where a=99;
+select 1, min(a) from t1m where 1=99;
+select 1, min(1) from t1m where a=99;
+select 1, min(1) from t1m where 1=99;
+
+select 1, max(a) from t1m where a=99;
+select 1, max(a) from t1m where 1=99;
+select 1, max(1) from t1m where a=99;
+select 1, max(1) from t1m where 1=99;
+
+# test with InnoDB
+select min(a) from t1i;
+select min(7) from t1i;
+select min(7) from DUAL;
+explain select min(7) from t2i join t1i;
+select min(7) from t2i join t1i;
+
+select max(a) from t1i;
+select max(7) from t1i;
+select max(7) from DUAL;
+explain select max(7) from t2i join t1i;
+select max(7) from t2i join t1i;
+
+select 1, min(a) from t1i where a=99;
+select 1, min(a) from t1i where 1=99;
+select 1, min(1) from t1i where a=99;
+select 1, min(1) from t1i where 1=99;
+
+select 1, max(a) from t1i where a=99;
+select 1, max(a) from t1i where 1=99;
+select 1, max(1) from t1i where a=99;
+select 1, max(1) from t1i where 1=99;
+
+# mixed MyISAM/InnoDB test
+explain select count(*), min(7), max(7) from t1m, t1i;
+select count(*), min(7), max(7) from t1m, t1i;
+
+explain select count(*), min(7), max(7) from t1m, t2i;
+select count(*), min(7), max(7) from t1m, t2i;
+
+explain select count(*), min(7), max(7) from t2m, t1i;
+select count(*), min(7), max(7) from t2m, t1i;
+
+drop table t1m, t1i, t2m, t2i;
+
# End of 4.1 tests