Skip to content

feature: expand sum Aggregate Function to int128_t #1226

@davidshiz

Description

@davidshiz

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Describe the problem

mysql> CREATE TABLE `test` (
    ->   `id` bigint(20) DEFAULT NULL
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test values(9223372036854775801);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values(9223372036854775802);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values(9223372036854775803);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values(9223372036854775804);
Query OK, 1 row affected (0.00 sec)

mysql> select *  from test;
+---------------------+
| id                  |
+---------------------+
| 9223372036854775801 |
| 9223372036854775802 |
| 9223372036854775803 |
| 9223372036854775804 |
+---------------------+
4 rows in set (0.00 sec)

mysql> SELECT SUM(id) FROM test;
ERROR 1105 (HY000): Aggregation overflow.
mysql> SELECT AVG(id) FROM test;
ERROR 2013 (HY000): Lost connection to MySQL server during query

Expected behavior

mysql> SELECT SUM(id) FROM test;
+----------------------+
| SUM(id)              |
+----------------------+
| 36893488147419103210 |
+----------------------+
1 row in set (0.00 sec)

mysql> SELECT AVG(id) FROM test;
+--------------------------+
| AVG(id)                  |
+--------------------------+
| 9223372036854775802.5000 |
+--------------------------+
1 row in set (0.00 sec)

How To Reproduce

CREATE TABLE `test` (
  `id` bigint(20) DEFAULT NULL
);
insert into test values(9223372036854775801);
insert into test values(9223372036854775802);
insert into test values(9223372036854775803);
insert into test values(9223372036854775804);
SELECT AVG(id) FROM test;
SELECT SUM(id) FROM test;

Environment

root@ub01:~# /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: 1fa9d3346
        Last commit time: Date:   Fri Jan 13 07:03:20 2023 +0000
        Build time: Date: Fri Jan 13 17:22:15 CST 2023
root@ub01:~# cat /etc/issue
Ubuntu 20.04.5 LTS \n \l

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

  • Yes, I will!

Metadata

Metadata

Assignees

Labels

A-featurefeature with good ideaB-storagedata type, data storage, insert,update,delete, transactionsC-stonedb-5.7associated with stonedb 5.7prio: normalMedium priority

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions