diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index 99c42bb83cf379cace7796ea1cccc3c531d4f99c..ef29d0f2f5bfa9ab11a238ccb108e2d43cabb134 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -256,3 +256,8 @@ bit_and(col) bit_or(col) 18446744073709551614 18446744073709551614 18446744073709551615 18446744073709551615 drop table t1; +create table t1 (a int); +select avg(2) from t1; +avg(2) +NULL +drop table t1; diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index d03e4b9b629fa8b906404241542616d92ffc18c2..c03c39bec4aa0b8e07156900175fdc4122b90939 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -155,3 +155,11 @@ insert into t1 values (-1), (-2), (-3); select bit_and(col), bit_or(col) from t1; select SQL_BIG_RESULT bit_and(col), bit_or(col) from t1 group by col; drop table t1; + +# +# Bug #3376: avg() and an empty table +# + +create table t1 (a int); +select avg(2) from t1; +drop table t1; diff --git a/sql/item_sum.h b/sql/item_sum.h index d3a328be032d7b92c103b158ced39339642eb59b..6835b1e8fae08fe557cbd3fee736e55611cededb 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -249,6 +249,7 @@ class Item_sum_avg :public Item_sum_num void update_field(); Item *result_item(Field *field) { return new Item_avg_field(this); } + void no_rows_in_result() {} const char *func_name() const { return "avg"; } unsigned int size_of() { return sizeof(*this);} };