Browse Source

Fixed LP bug #777654.

The method Item_sum_num::fix_fields() calculated the value of
the flag Item_sum_num::maybe_null in some cases incorrectly.
pull/843/head
Igor Babaev 14 years ago
parent
commit
5ab628e024
  1. 12
      mysql-test/r/sum_distinct.result
  2. 12
      mysql-test/t/sum_distinct.test
  3. 3
      sql/item_sum.cc

12
mysql-test/r/sum_distinct.result

@ -95,3 +95,15 @@ SELECT SUM(DISTINCT id % 11) FROM t1;
SUM(DISTINCT id % 11)
55
DROP TABLE t1;
#
# Bug #777654: empty subselect in FROM clause returning
# SUM(DISTINCT) over non-nullable field
#
CREATE TABLE t1 (a int NOT NULL) ;
SELECT SUM(DISTINCT a) FROM t1;
SUM(DISTINCT a)
NULL
SELECT * FROM (SELECT SUM(DISTINCT a) FROM t1) AS t;
SUM(DISTINCT a)
NULL
DROP TABLE t1;

12
mysql-test/t/sum_distinct.test

@ -93,3 +93,15 @@ SELECT SUM(DISTINCT id) FROM t1;
SELECT SUM(DISTINCT id % 11) FROM t1;
DROP TABLE t1;
--echo #
--echo # Bug #777654: empty subselect in FROM clause returning
--echo # SUM(DISTINCT) over non-nullable field
--echo #
CREATE TABLE t1 (a int NOT NULL) ;
SELECT SUM(DISTINCT a) FROM t1;
SELECT * FROM (SELECT SUM(DISTINCT a) FROM t1) AS t;
DROP TABLE t1;

3
sql/item_sum.cc

@ -568,13 +568,12 @@ Item_sum_num::fix_fields(THD *thd, Item **ref)
return TRUE;
decimals=0;
maybe_null=0;
maybe_null= sum_func() != COUNT_FUNC;
for (uint i=0 ; i < arg_count ; i++)
{
if (args[i]->fix_fields(thd, args + i) || args[i]->check_cols(1))
return TRUE;
set_if_bigger(decimals, args[i]->decimals);
maybe_null |= args[i]->maybe_null;
}
result_field=0;
max_length=float_length(decimals);

Loading…
Cancel
Save