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.
parent 6a304f3f
......@@ -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
......@@ -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
......@@ -701,12 +701,11 @@ class Item {
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; }
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment