From 294ae90d9c8e997f481a982fde926203864b4591 Mon Sep 17 00:00:00 2001 From: "ramil/ram@mysql.com/ramil.myoffice.izhnet.ru" <> Date: Fri, 22 Dec 2006 09:29:28 +0400 Subject: [PATCH] Fix for bug #21976: Unnecessary warning with count(decimal) We use val_int() calls (followed by null_value check) to determine nullness in some Item_sum_count' and Item_sum_count_distinct' methods, as a side effect we get extra warnings raised in the val_int(). Fix: use is_null() instead. --- mysql-test/r/func_group.result | 10 ++++++++++ mysql-test/t/func_group.test | 11 +++++++++++ sql/item.h | 11 +++++------ sql/item_sum.cc | 32 +++++--------------------------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index c6117053a60..a15801f6960 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -1029,3 +1029,13 @@ t1 CREATE TABLE `t1` ( `stddev(0)` double(8,4) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +create table t1 (a decimal(20)); +insert into t1 values (12345678901234567890); +select count(a) from t1; +count(a) +1 +select count(distinct a) from t1; +count(distinct a) +1 +drop table t1; +End of 5.0 tests diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 079d107fad8..a47fd028b92 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -700,3 +700,14 @@ create table t1 select stddev(0); show create table t1; drop table t1; +# +# Bug #21976: Unnecessary warning with count(decimal) +# + +create table t1 (a decimal(20)); +insert into t1 values (12345678901234567890); +select count(a) from t1; +select count(distinct a) from t1; +drop table t1; + +--echo End of 5.0 tests diff --git a/sql/item.h b/sql/item.h index 0cfb0b01fd8..eb98ecd6021 100644 --- a/sql/item.h +++ b/sql/item.h @@ -701,12 +701,11 @@ public: virtual bool get_date_result(TIME *ltime,uint fuzzydate) { return get_date(ltime,fuzzydate); } /* - This function is used only in Item_func_isnull/Item_func_isnotnull - (implementations of IS NULL/IS NOT NULL clauses). Item_func_is{not}null - calls this method instead of one of val/result*() methods, which - normally will set null_value. This allows to determine nullness of - a complex expression without fully evaluating it. - Any new item which can be NULL must implement this call. + The method allows to determine nullness of a complex expression + without fully evaluating it, instead of calling val/result*() then + checking null_value. Used in Item_func_isnull/Item_func_isnotnull + and Item_sum_count/Item_sum_count_distinct. + Any new item which can be NULL must implement this method. */ virtual bool is_null() { return 0; } diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 77c6e17607f..f7a92f16b29 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1034,14 +1034,8 @@ void Item_sum_count::clear() bool Item_sum_count::add() { - if (!args[0]->maybe_null) + if (!args[0]->maybe_null || !args[0]->is_null()) count++; - else - { - (void) args[0]->val_int(); - if (!args[0]->null_value) - count++; - } return 0; } @@ -1941,14 +1935,8 @@ void Item_sum_count::reset_field() char *res=result_field->ptr; longlong nr=0; - if (!args[0]->maybe_null) + if (!args[0]->maybe_null || !args[0]->is_null()) nr=1; - else - { - (void) args[0]->val_int(); - if (!args[0]->null_value) - nr=1; - } int8store(res,nr); } @@ -2051,14 +2039,8 @@ void Item_sum_count::update_field() char *res=result_field->ptr; nr=sint8korr(res); - if (!args[0]->maybe_null) + if (!args[0]->maybe_null || !args[0]->is_null()) nr++; - else - { - (void) args[0]->val_int(); - if (!args[0]->null_value) - nr++; - } int8store(res,nr); } @@ -2531,12 +2513,8 @@ bool Item_sum_count_distinct::setup(THD *thd) Item *item=args[i]; if (list.push_back(item)) return TRUE; // End of memory - if (item->const_item()) - { - (void) item->val_int(); - if (item->null_value) - always_null=1; - } + if (item->const_item() && item->is_null()) + always_null= 1; } if (always_null) return FALSE;