Open davidshiz opened 1 year ago
UNSIGNED bigint also have this problem
ref #1125
create table test(u_bigcustkey BIGINT);
insert into test values(4073709000001),(4073709000004),(4073709000009);
select avg(u_bigcustKey) from test;
mysql> select avg(u_bigcustKey) from test;
+--------------------+
| avg(u_bigcustKey) |
+--------------------+
| 4073709000004.6667 |
+--------------------+
1 row in set (0.00 sec)
When overflow_check
> std::numeric_limits
void AggregatorSum64::PutAggregatedValue(unsigned char *buf, int64_t v, int64_t factor) {
stats_updated = false;
int64_t *p = (int64_t *)buf;
if (*p == common::NULL_VALUE_64) {
*p = 0;
}
double overflow_check = double(*p) + double(v) * factor;
if (overflow_check > std::numeric_limits<std::streamsize>::max() ||
overflow_check < std::numeric_limits<std::streamsize>::min())
throw common::NotImplementedException("Aggregation overflow.");
*p += v * factor;
}
To solve the exception, overflow_check should be extended to int128_t
, like: std::numeric_limits<int128_t>::max()
.
For sum64 or sum32 or sumdecimal, we should reset total_width
, grouping_and_UTF_width
to 16 bytes length(to store int128_t)
In void GroupTable::Initialize(int64_t max_no_groups, bool parallel_allowed) {
// Aggregators
for (int i = no_grouping_attr; i < no_attr; i++) {
aggregated_col_offset[i] = total_width - grouping_and_UTF_width;
total_width += aggregator[i]->BufferByteSize();
total_width = 4 * ((total_width + 3) / 4); // e.g. 1->4, 12->12, 19->20
}
But will these buffer changes cause unknown problems?
We do this feat after decimal128 supported.
Have you read the Contributing Guidelines on issues?
Please confirm if bug report does NOT exists already ?
Describe the problem
Expected behavior
How To Reproduce
Environment
Are you interested in submitting a PR to solve the problem?