Commit 5ab628e0 authored by Igor Babaev's avatar Igor Babaev

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.
parent 31805e62
......@@ -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;
......@@ -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;
......@@ -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);
......
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