From 86e9dc29b0c09a45a0aee85c96eb1ede650db45a Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Mon, 7 Jun 2004 12:38:35 +0200 Subject: [PATCH] BUG#3987 - if(int, aggregate(int)) --- mysql-test/r/func_if.result | 6 ++++++ mysql-test/t/func_if.test | 9 +++++++++ sql/item_cmpfunc.cc | 4 ++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result index 470004d2646..aee54ede324 100644 --- a/mysql-test/r/func_if.result +++ b/mysql-test/r/func_if.result @@ -58,3 +58,9 @@ select min(if(y -x > 5,y,NULL)), max(if(y - x > 5,y,NULL)) from t1; min(if(y -x > 5,y,NULL)) max(if(y - x > 5,y,NULL)) 6 56 drop table t1; +create table t1 (a int); +insert t1 values (1),(2); +select if(1>2,a,avg(a)) from t1; +if(1>2,a,avg(a)) +1.5000 +drop table t1; diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test index 1f95239bf4b..5e605dbe97b 100644 --- a/mysql-test/t/func_if.test +++ b/mysql-test/t/func_if.test @@ -38,3 +38,12 @@ create table t1 (x int, y int); insert into t1 values (0,6),(10,16),(20,26),(30,10),(40,46),(50,56); select min(if(y -x > 5,y,NULL)), max(if(y - x > 5,y,NULL)) from t1; drop table t1; + +# +# BUG#3987 +# +create table t1 (a int); +insert t1 values (1),(2); +select if(1>2,a,avg(a)) from t1; +drop table t1; + diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index d84dab3425a..013304d9df5 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -535,8 +535,8 @@ Item_func_if::fix_length_and_dec() decimals=max(args[1]->decimals,args[2]->decimals); enum Item_result arg1_type=args[1]->result_type(); enum Item_result arg2_type=args[2]->result_type(); - bool null1=args[1]->null_value; - bool null2=args[2]->null_value; + bool null1=args[1]->const_item() && args[1]->null_value; + bool null2=args[2]->const_item() && args[2]->null_value; if (null1) {