List:Commits« Previous MessageNext Message »
From:ramil Date:March 6 2006 1:38pm
Subject:bk commit into 4.1 tree (ramil:1.2460) BUG#17896
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of ram. When ram does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2460 06/03/06 16:38:35 ramil@stripped +3 -0
  Fix for bug #17896: MIN of CASE WHEN returns non-minimum value!

  sql/item_cmpfunc.cc
    1.206 06/03/06 16:38:28 ramil@stripped +15 -4
    Fix for bug #17896: MIN of CASE WHEN returns non-minimum value!
    - NULL items should not affect the result type.

  mysql-test/t/case.test
    1.17 06/03/06 16:38:28 ramil@stripped +11 -0
    Fix for bug #17896: MIN of CASE WHEN returns non-minimum value!

  mysql-test/r/case.result
    1.17 06/03/06 16:38:28 ramil@stripped +8 -0
    Fix for bug #17896: MIN of CASE WHEN returns non-minimum value!

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	ramil
# Host:	myoffice.izhnet.ru
# Root:	/usr/home/ram/work/4.1.b17896

--- 1.205/sql/item_cmpfunc.cc	2006-01-14 05:55:01 +04:00
+++ 1.206/sql/item_cmpfunc.cc	2006-03-06 16:38:28 +04:00
@@ -37,10 +37,21 @@ static Item_result item_store_type(Item_
 
 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;
+
+  /* Note: NULL items don't affect the result type */
+  *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;
+    }
+  for (; item < item_end; item++)
+    if ((*item)->type() != Item::NULL_ITEM)
+      *type= item_store_type(type[0], (*item)->result_type());
 }
 
 static void agg_cmp_type(Item_result *type, Item **items, uint nitems)

--- 1.16/mysql-test/r/case.result	2005-06-20 14:43:35 +05:00
+++ 1.17/mysql-test/r/case.result	2006-03-06 16:38:28 +04:00
@@ -169,3 +169,11 @@ SELECT CASE '1' WHEN '2' THEN 'BUG' ELSE
 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;

--- 1.16/mysql-test/t/case.test	2005-07-28 05:21:39 +05:00
+++ 1.17/mysql-test/t/case.test	2006-03-06 16:38:28 +04:00
@@ -119,4 +119,15 @@ 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
Thread
bk commit into 4.1 tree (ramil:1.2460) BUG#17896ramil6 Mar