stoneatom / stonedb

StoneDB is an Open-Source MySQL HTAP and MySQL-Native DataBase for OLTP, Real-Time Analytics, a counterpart of MySQLHeatWave. (https://stonedb.io)
https://stonedb.io/
GNU General Public License v2.0
862 stars 139 forks source link

bug: DECIMAL type, the AVG() aggregate function return result set error #927

Open davidshiz opened 1 year ago

davidshiz commented 1 year ago

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

Describe the problem

The wrong result is as follows:

mysql> select avg(d2) from cs1;
+----------------------+
| avg(d2)              |
+----------------------+
| 24031.61829363636200 |
+----------------------+
1 row in set (0.00 sec)

Expected behavior

the right answer is

mysql> select avg(d2) from cs1;
+----------------------+
| avg(d2)              |
+----------------------+
| 24031.61829363636364 |
+----------------------+
1 row in set (0.00 sec)

How To Reproduce

CREATE TABLE cs1 (d1 DECIMAL(17), d2 DECIMAL(17,10), d3 DECIMAL(17,16), d4 DECIMAL(17),d5 DECIMAL(17),i1 INT) ;

INSERT INTO cs1 VALUES
(1234,5678,-0.123456789012345,2,1,1),
(1234,-5678,0.12345678901234,2,1,1),
(1234567890123,123456.90123,0.12345678901234,2,1,1),
(NULL,NULL,NULL,2,1,1),
(0,0,0,2,1,1),
(1234,5678,0.123456789,3,2,2),
(-12345678923,-5678,0.1234567890121,3,2,2),
(56789012,123856.90,0.12345678909,3,2,2),
(NULL,NULL,NULL,3,2,2),
(0,0,0,3,2,2),
(1234,5678,-0.123456789012345,1111111111,1,1),
(1234,5678,-0.123456789012345,1111111111,1,1),
(1234,5678,-0.123456789012345,1111111112,1,1);

select avg(d2) from cs1;

Environment

root@localhost:/# /stonedb57/install/bin/mysqld --version
/stonedb57/install/bin/mysqld  Ver 5.7.36-StoneDB for Linux on x86_64 (build-)
build information as follow:
        Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7-dev
        Branch name: stonedb-5.7-dev
        Last commit ID: d0c2e01b6
        Last commit time: Date:   Wed Nov 2 19:58:00 2022 +0800
        Build time: Date: Sun 06 Nov 2022 08:50:06 AM UTC
root@ub01:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"

Are you interested in submitting a PR to solve the problem?

adofsauron commented 1 year ago

@duanfuxiang0 DECIMAL ? would you please have a look of DECIMAL ?

RingsC commented 1 year ago

All issues about decimal can be fixed after the decimal type supported.

hustjieke commented 1 year ago

Related to #456 , to make the result correct, we need impl decimal128 to expand max precision to 38.