Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Won't Fix
-
1.4.3
-
None
Description
MariaDB [tpch1]> select 'Avg', avg(n_regionkey) from nation;
---------------------+
| Avg | avg(n_regionkey) |
---------------------+
| Avg | 2.0000 |
---------------------+
1 row in set (0.025 sec)
Notice there are four decimal places, which is correct.
Now see
MariaDB [tpch1]> select 'Max', max(n_regionkey) from nation
-> union
-> select 'Avg', avg(n_regionkey) from nation
-> ;
---------------------+
| Max | max(n_regionkey) |
---------------------+
| Max | 4.0000 |
| Avg | 2.0000 |
---------------------+
2 rows in set (0.023 sec)
Which puts 4 decimal places for both. Presumably, the MAX (an INT) is promoted to long double.
When used this way
select 'Avg', avg(n_regionkey) from nation
union
(select n_nationkey,n_name from nation where n_regionkey = 0) order by 1, 2;
----------------------+
| Avg | avg(n_regionkey) |
----------------------+
| 0 | ALGERIA |
| 14 | KENYA |
| 15 | MOROCCO |
| 16 | MOZAMBIQUE |
| 5 | ETHIOPIA |
| Avg | 2.000000000 |
----------------------+
6 rows in set (0.026 sec)
Which gives us the odd number of 9 decimals.
See working_tpch1_compareLogOnly/qa/DL_union.sql.ref.log.