Closed satanson closed 2 years ago
It caused by overflow of bigint,
mysql> select sum(cast(c1 as largeint)), count(c1), sum(cast(c1 as largeint))/count(c1), avg(c1) from t0;
+---------------------------+-----------+-------------------------------------------+-----------------------+
| sum(CAST(c1 AS LARGEINT)) | count(c1) | (sum(CAST(c1 AS LARGEINT))) / (count(c1)) | avg(c1) |
+---------------------------+-----------+-------------------------------------------+-----------------------+
| 480728365192791144313 | 160 | 3.004552282454945e+18 | 3.004552282454945e+18 |
+---------------------------+-----------+-------------------------------------------+-----------------------+
Steps to reproduce the behavior (Required)
Expected behavior (Required)
Real behavior (Required)
when number of rows increase, avg gives a unstable answer. we use tpcds_100g; Q1: select avg(ws_promo_sk), sum(ws_promo_sk)/count(ws_promo_sk) from web_sales;
Q2: select avg(cast(ws_promo_sk4294967296 as bigint)), sum(cast(ws_promo_sk4294967296 as bigint))/count(ws_promo_sk) from web_sales;
Q3: select avg(cast(ws_promo_sk429496729600000000000 as largeint)), sum(cast(ws_promo_sk429496729600000000000 as largeint))/count(ws_promo_sk) from web_sales;
StarRocks version (Required)