summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2003-02-03 20:20:32 +0200
committerunknown <monty@mashka.mysql.fi>2003-02-03 20:20:32 +0200
commitc73dcb5e3018374e8c1a8ae57b32483cb4f62be4 (patch)
tree9969b64873b025006c1eb0dba4dddc67e5501c19 /mysql-test
parentac4dacaa29f8f7ee2b5ed7c56815ee343d4b8d82 (diff)
downloadmariadb-git-c73dcb5e3018374e8c1a8ae57b32483cb4f62be4.tar.gz
Fix for MIN/MAX with empty tables
MIN(key_column) could in some cases return NULL on a column with NULL and other values. MIN(key_column) and MAX(key_column) could in some cases return wrong values when used in OUTER JOIN. configure.in: Updated version number libmysqld/libmysqld.c: Portability fix (for windows) mysql-test/r/func_group.result: Added test case for MIN/MAX problems mysql-test/t/func_group.test: Added test case for MIN/MAX problems sql/item.h: Fix for MIN/MAX with empty tables sql/item_sum.h: Fix for MIN/MAX with empty tables sql/opt_sum.cc: MIN(key_column) could in some cases return NULL on a column with NULL and other values. MIN(key_column) and MAX(key_column) could in some cases return wrong values when used in OUTER JOIN. sql/sql_select.cc: Fix for MIN/MAX with empty tables
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/func_group.result53
-rw-r--r--mysql-test/t/func_group.test27
2 files changed, 80 insertions, 0 deletions
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index c1f36283ab0..8263df36105 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -151,3 +151,56 @@ sum(num)
45.63
51.80
drop table t1;
+create table t1 (a1 int, a2 char(3), key k1(a1), key k2(a2));
+insert into t1 values(10,'aaa'), (10,null), (10,'bbb'), (20,'zzz');
+create table t2(a1 char(3), a2 int, a3 real, key k1(a1), key k2(a2, a1));
+select * from t1;
+a1 a2
+10 aaa
+10 NULL
+10 bbb
+20 zzz
+select min(a2) from t1;
+min(a2)
+aaa
+select max(t1.a1), max(t2.a2) from t1, t2;
+max(t1.a1) max(t2.a2)
+NULL NULL
+select max(t1.a1) from t1, t2;
+max(t1.a1)
+NULL
+select max(t2.a2), max(t1.a1) from t1, t2;
+max(t2.a2) max(t1.a1)
+NULL NULL
+explain select min(a2) from t1;
+Comment
+Select tables optimized away
+explain select max(t1.a1), max(t2.a2) from t1, t2;
+Comment
+No matching min/max row
+insert into t2 values('AAA', 10, 0.5);
+select max(t1.a1), max(t2.a1) from t1, t2 where t2.a2=9;
+max(t1.a1) max(t2.a1)
+NULL NULL
+select max(t2.a1), max(t1.a1) from t1, t2 where t2.a2=9;
+max(t2.a1) max(t1.a1)
+NULL NULL
+select t1.a1, t1.a2, t2.a1, t2.a2 from t1 left outer join t2 on t1.a1=10;
+a1 a2 a1 a2
+10 aaa AAA 10
+10 NULL AAA 10
+10 bbb AAA 10
+20 zzz NULL NULL
+select max(t1.a2) from t1 left outer join t2 on t1.a1=10;
+max(t1.a2)
+zzz
+select max(t1.a2) from t1 left outer join t2 on t1.a1=10 where t1.a1=20;
+max(t1.a2)
+zzz
+select max(t1.a2) from t1 left outer join t2 on t1.a1=10 where t1.a1=10;
+max(t1.a2)
+bbb
+select max(t2.a1) from t1 left outer join t2 on t1.a2=t2.a1 and 1=0 where t2.a1='AAA';
+max(t2.a1)
+NULL
+drop table t1,t2;
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index 57e9ae24e08..04a2ff68a92 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -99,3 +99,30 @@ insert into t1 values (5.2,'nem'),(8.64,'monty'),(11.12,'sinisa');
select sum(num) from t1;
select sum(num) from t1 group by user;
drop table t1;
+
+#
+# Test problem with MIN() optimization in case of null values
+#
+
+create table t1 (a1 int, a2 char(3), key k1(a1), key k2(a2));
+insert into t1 values(10,'aaa'), (10,null), (10,'bbb'), (20,'zzz');
+create table t2(a1 char(3), a2 int, a3 real, key k1(a1), key k2(a2, a1));
+select * from t1;
+# The following returned NULL in 4.0.10
+select min(a2) from t1;
+select max(t1.a1), max(t2.a2) from t1, t2;
+select max(t1.a1) from t1, t2;
+select max(t2.a2), max(t1.a1) from t1, t2;
+
+explain select min(a2) from t1;
+explain select max(t1.a1), max(t2.a2) from t1, t2;
+
+insert into t2 values('AAA', 10, 0.5);
+select max(t1.a1), max(t2.a1) from t1, t2 where t2.a2=9;
+select max(t2.a1), max(t1.a1) from t1, t2 where t2.a2=9;
+select t1.a1, t1.a2, t2.a1, t2.a2 from t1 left outer join t2 on t1.a1=10;
+select max(t1.a2) from t1 left outer join t2 on t1.a1=10;
+select max(t1.a2) from t1 left outer join t2 on t1.a1=10 where t1.a1=20;
+select max(t1.a2) from t1 left outer join t2 on t1.a1=10 where t1.a1=10;
+select max(t2.a1) from t1 left outer join t2 on t1.a2=t2.a1 and 1=0 where t2.a1='AAA';
+drop table t1,t2;