summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2014-03-23 19:43:01 +0400
committerAlexander Barkov <bar@mariadb.org>2014-03-23 19:43:01 +0400
commitce3c457e6d6f282967154cd7a56d1382c652cb2b (patch)
tree15da340214c2b54f86046cc18a964f43e68f5e0b
parent92bd6801b9315607ab7f2af2ea45066a3ffbd70b (diff)
downloadmariadb-git-ce3c457e6d6f282967154cd7a56d1382c652cb2b.tar.gz
MDEV-5781 Item_sum_std::val_real(): Assertion `nr >= 0.0' fails on query with STDDEV_POP, ROUND and variable
-rw-r--r--mysql-test/r/func_math.result15
-rw-r--r--mysql-test/t/func_math.test18
-rw-r--r--sql/item_func.cc3
3 files changed, 36 insertions, 0 deletions
diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result
index 04e71a715ce..23a1f1bc4b3 100644
--- a/mysql-test/r/func_math.result
+++ b/mysql-test/r/func_math.result
@@ -756,3 +756,18 @@ select 5 div 2.0;
select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
5.9 div 2 1.23456789e3 DIV 2 1.23456789e9 DIV 2 1.23456789e19 DIV 2
2 617 617283945 6172839450000000000
+#
+# End of 5.5 tests
+#
+#
+# Start of 10.0 tests
+#
+#
+# MDEV-5781 Item_sum_std::val_real(): Assertion `nr >= 0.0' fails on query with STDDEV_POP, ROUND and variable
+#
+SELECT STDDEV_POP(ROUND(0,@A:=2009)) FROM (SELECT 1 UNION SELECT 2) fake_table;
+STDDEV_POP(ROUND(0,@A:=2009))
+0.0000
+#
+# End of 10.0 tests
+#
diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test
index b843cf8c364..92ef362c32c 100644
--- a/mysql-test/t/func_math.test
+++ b/mysql-test/t/func_math.test
@@ -559,3 +559,21 @@ select 5.0 div 2.0;
select 5.0 div 2;
select 5 div 2.0;
select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
+
+--echo #
+--echo # End of 5.5 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-5781 Item_sum_std::val_real(): Assertion `nr >= 0.0' fails on query with STDDEV_POP, ROUND and variable
+--echo #
+SELECT STDDEV_POP(ROUND(0,@A:=2009)) FROM (SELECT 1 UNION SELECT 2) fake_table;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 2fe47406b9e..c659d7964b9 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2666,6 +2666,9 @@ double my_double_round(double value, longlong dec, bool dec_unsigned,
volatile double value_div_tmp= value / tmp;
volatile double value_mul_tmp= value * tmp;
+ if (!dec_negative && my_isinf(tmp)) // "dec" is too large positive number
+ return value;
+
if (dec_negative && my_isinf(tmp))
tmp2= 0.0;
else if (!dec_negative && my_isinf(value_mul_tmp))