diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index 5192251795b..57b109e1ee6 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -648,3 +648,11 @@ select a from t1 having a=1; a 1 drop table t1; +create table t1 (a int); +select variance(2) from t1; +variance(2) +NULL +select stddev(2) from t1; +stddev(2) +NULL +drop table t1; diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index a1acf5f89eb..7966a2262f4 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -387,3 +387,12 @@ insert into t1 values (1); select max(a) as b from t1 having b=1; select a from t1 having a=1; drop table t1; + +# +# Bug #3435: variance(const), stddev(const) and an empty table +# + +create table t1 (a int); +select variance(2) from t1; +select stddev(2) from t1; +drop table t1; diff --git a/sql/item_sum.h b/sql/item_sum.h index 9593c8ddbba..d7753303f55 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -351,6 +351,7 @@ class Item_sum_variance : public Item_sum_num void update_field(); Item *result_item(Field *field) { return new Item_variance_field(this); } + void no_rows_in_result() {} const char *func_name() const { return "variance"; } Item *copy_or_same(THD* thd); };