MySQL SUM of type REAL may return inconsistent results

For a column with large real values, MySQL will return 0 for its sum, but if it is enclosed in a subquery, a nonzero result is returned. I know that usually overflow cases are undefined, but it seems strange to me that MySQL will return different results depending on whether the query is simple or contains a subquery.

create table z (f_real real);
insert into z values (1.80309068027e307),(1.44090607633e308),(1.59586958712e308);
select sum(f_real) from z;
+-------------+
| sum(f_real) |
+-------------+
|           0 |
+-------------+
select * from (select sum(f_real) from z) t;
+------------------------+
| sum(f_real)            |
+------------------------+
| 1.7976931348623157e308 |
+------------------------+
+4
source share
1 answer

Well, I think this is due to a ceiling hit in the amount that SUM can handle.

For example: insert into the values ​​z (1.80309068027e307), (1.44090607633e307), (1.59586958712e307);

works great.

z (1.80309068027e308), (1.44090607633e307), (1.59586958712e307);

, 1.80309068027e308 . , .

, , , , , 0, ?

0

All Articles