summaryrefslogtreecommitdiff
path: root/storage/sequence
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2016-02-22 12:52:29 +0100
committerSergei Golubchik <serg@mariadb.org>2016-02-23 10:54:35 +0100
commite6d51aac778f7c59b0f737f7504a52b0baf07544 (patch)
tree4d70662d815a68c43225544081f7542227597f4d /storage/sequence
parent9214d043fd864f8ee96e34551e49a011e20ddef0 (diff)
downloadmariadb-git-e6d51aac778f7c59b0f737f7504a52b0baf07544.tar.gz
MDEV-9550 COUNT(NULL) returns incorrect result with sequence storage engine
when calculating COUNT(basic_const), take into account that this basic_const may be NULL
Diffstat (limited to 'storage/sequence')
-rw-r--r--storage/sequence/mysql-test/sequence/group_by.result8
-rw-r--r--storage/sequence/mysql-test/sequence/group_by.test7
-rw-r--r--storage/sequence/sequence.cc6
3 files changed, 18 insertions, 3 deletions
diff --git a/storage/sequence/mysql-test/sequence/group_by.result b/storage/sequence/mysql-test/sequence/group_by.result
index 86bb158d9fc..b3b56338aef 100644
--- a/storage/sequence/mysql-test/sequence/group_by.result
+++ b/storage/sequence/mysql-test/sequence/group_by.result
@@ -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
diff --git a/storage/sequence/mysql-test/sequence/group_by.test b/storage/sequence/mysql-test/sequence/group_by.test
index 870afd9ed89..b2e04037a8b 100644
--- a/storage/sequence/mysql-test/sequence/group_by.test
+++ b/storage/sequence/mysql-test/sequence/group_by.test
@@ -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;
diff --git a/storage/sequence/sequence.cc b/storage/sequence/sequence.cc
index 7b20615b15f..8d9465f08c5 100644
--- a/storage/sequence/sequence.cc
+++ b/storage/sequence/sequence.cc
@@ -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: