Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: sum aggregation cause overflow panic #517

Open
Fedomn opened this issue Feb 22, 2022 · 2 comments
Open

executor: sum aggregation cause overflow panic #517

Fedomn opened this issue Feb 22, 2022 · 2 comments

Comments

@Fedomn
Copy link
Member

Fedomn commented Feb 22, 2022

Currently, our sum aggregation used the primitive datatype add function to calculate results. So sometimes the calculation will cause overflow panic.

Maybe we need to use the Decimal or Float64 type for the sum calculation.

Minimal reproduce step

create table t (v int);
insert into t values (2147483647), (2), (3);
select sum(v) from t;
-- thread 'tokio-runtime-worker' panicked at 'attempt to add with overflow', src/executor/aggregation/sum.rs:36:1

What did you expect to see?

create table t (v int);
insert into t values (2147483647), (2), (3);

select sum(v) from t;
+------------+
| sum(v)     |
+------------+
| 2147483652 |
+------------+
@skyzh
Copy link
Member

skyzh commented Feb 22, 2022

We can follow the Postgres convention. IIRC, it will use i64 to sum i32 and use Decimal to sum i64.

I think we can start working on it when we have a fully functional expression framework. Currently, it's hard to write such aggregation in our system.

@Fedomn
Copy link
Member Author

Fedomn commented Feb 23, 2022

Just link Postgres convention docs https://www.postgresql.org/docs/current/functions-aggregate.html

It used numeric for sum(bigint) and avg(bigint), and numeric seems similar with decimal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants