Skip to content

Commit

Permalink
MDEV-9550 COUNT(NULL) returns incorrect result with sequence storage …
Browse files Browse the repository at this point in the history
…engine

when calculating COUNT(basic_const), take into account that
this basic_const may be NULL
  • Loading branch information
vuvova committed Feb 23, 2016
1 parent 9214d04 commit e6d51aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion storage/sequence/mysql-test/sequence/group_by.result
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select count(*) from seq_1_to_15_step_2 group by mod(seq,2);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE seq_1_to_15_step_2 index NULL PRIMARY 8 NULL 8 Using index; Using temporary; Using filesort
drop table seq_1_to_15_step_2;
create temporary table t1 select * from seq_1_to_3;
select count(NULL) from t1;
count(NULL)
0
select count(NULL) from seq_1_to_3;
count(NULL)
0
7 changes: 6 additions & 1 deletion storage/sequence/mysql-test/sequence/group_by.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ explain select count(*) from seq_1_to_15_step_2, seq_1_to_15_step_2 as t2;
explain select count(*) from seq_1_to_15_step_2 where seq > 0;
explain select count(*) from seq_1_to_15_step_2 group by mod(seq,2);

drop table seq_1_to_15_step_2;
#
# MDEV-9550 COUNT(NULL) returns incorrect result with sequence storage engine
#
create temporary table t1 select * from seq_1_to_3;
select count(NULL) from t1;
select count(NULL) from seq_1_to_3;
6 changes: 5 additions & 1 deletion storage/sequence/sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,11 @@ int ha_seq_group_by_handler::next_row()
switch (item_sum->sum_func()) {
case Item_sum::COUNT_FUNC:
{
field->store((longlong) elements, 1);
Item *arg0= ((Item_sum*) item_sum)->get_arg(0);
if (arg0->basic_const_item() && arg0->is_null())
field->store(0LL, 1);
else
field->store((longlong) elements, 1);
break;
}
case Item_sum::SUM_FUNC:
Expand Down

0 comments on commit e6d51aa

Please sign in to comment.