[MCOL-3946] Wrong number decimals in UNION of AVG Created: 2020-04-14  Updated: 2023-11-21  Resolved: 2023-10-25

Status: Closed
Project: MariaDB ColumnStore
Component/s: ExeMgr
Affects Version/s: 1.4.3
Fix Version/s: Icebox

Type: Bug Priority: Minor
Reporter: David Hall (Inactive) Assignee: Leonid Fedorov
Resolution: Won't Fix Votes: 0
Labels: 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.



 Comments   
Comment by David Hall (Inactive) [ 2022-10-12 ]

The problem probably stems from the fact that avg here is "promoted" to string, which loses the internal decimal count.

Generated at Thu Feb 08 02:46:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.