summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknielsen@mysql.com <>2006-04-24 23:51:47 +0200
committerknielsen@mysql.com <>2006-04-24 23:51:47 +0200
commit854cbe88b62a5ca0529ce8d7d18a71a967ba4641 (patch)
treec36acaddf0636985ab3b939b2bbad6b73d79d9c4
parent497b91d60d353dc72e3f0da49b9a81e26e247e4f (diff)
parent17a80c9da4b70af717c5620445f0275c824be47f (diff)
downloadmariadb-git-854cbe88b62a5ca0529ce8d7d18a71a967ba4641.tar.gz
Merge mysql.com:/usr/local/mysql/mysql-4.1
into mysql.com:/usr/local/mysql/mysql-5.0-mtr-fix
-rwxr-xr-xmysql-test/mysql-test-run.pl2
-rw-r--r--mysql-test/r/case.result8
-rw-r--r--mysql-test/t/case.test11
-rw-r--r--sql/item_cmpfunc.cc23
4 files changed, 39 insertions, 5 deletions
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index ea0e11a69d9..a4688e37f11 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -3302,7 +3302,7 @@ sub valgrind_arguments {
if ( $opt_valgrind_options )
{
- mtr_add_arg($args, split(' ', $opt_valgrind_options));
+ mtr_add_arg($args, '%s', $_) for (split(' ', $opt_valgrind_options));
}
diff --git a/mysql-test/r/case.result b/mysql-test/r/case.result
index ea80695ad7b..8349d6e9338 100644
--- a/mysql-test/r/case.result
+++ b/mysql-test/r/case.result
@@ -175,6 +175,14 @@ SELECT CASE '1' WHEN '2' THEN 'BUG' ELSE 'nobug' END;
case+union+test
case+union+test
nobug
+create table t1(a float, b int default 3);
+insert into t1 (a) values (2), (11), (8);
+select min(a), min(case when 1=1 then a else NULL end),
+min(case when 1!=1 then NULL else a end)
+from t1 where b=3 group by b;
+min(a) min(case when 1=1 then a else NULL end) min(case when 1!=1 then NULL else a end)
+2 2 2
+drop table t1;
CREATE TABLE t1 (EMPNUM INT);
INSERT INTO t1 VALUES (0), (2);
CREATE TABLE t2 (EMPNUM DECIMAL (4, 2));
diff --git a/mysql-test/t/case.test b/mysql-test/t/case.test
index 555e34d5cf2..fbe1ee2b8c8 100644
--- a/mysql-test/t/case.test
+++ b/mysql-test/t/case.test
@@ -122,6 +122,17 @@ SELECT 'case+union+test'
UNION
SELECT CASE '1' WHEN '2' THEN 'BUG' ELSE 'nobug' END;
+#
+# Bug #17896: problem with MIN(CASE...)
+#
+
+create table t1(a float, b int default 3);
+insert into t1 (a) values (2), (11), (8);
+select min(a), min(case when 1=1 then a else NULL end),
+ min(case when 1!=1 then NULL else a end)
+from t1 where b=3 group by b;
+drop table t1;
+
# End of 4.1 tests
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 590a98777dd..54e281a1f14 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -41,10 +41,25 @@ static Item_result item_store_type(Item_result a,Item_result b)
static void agg_result_type(Item_result *type, Item **items, uint nitems)
{
- uint i;
- type[0]= items[0]->result_type();
- for (i=1 ; i < nitems ; i++)
- type[0]= item_store_type(type[0], items[i]->result_type());
+ Item **item, **item_end;
+
+ *type= STRING_RESULT;
+ /* Skip beginning NULL items */
+ for (item= items, item_end= item + nitems; item < item_end; item++)
+ {
+ if ((*item)->type() != Item::NULL_ITEM)
+ {
+ *type= (*item)->result_type();
+ item++;
+ break;
+ }
+ }
+ /* Combine result types. Note: NULL items don't affect the result */
+ for (; item < item_end; item++)
+ {
+ if ((*item)->type() != Item::NULL_ITEM)
+ *type= item_store_type(type[0], (*item)->result_type());
+ }
}