imay commented on a change in pull request #1889: Enhance the speed of avg function URL: https://github.com/apache/incubator-doris/pull/1889#discussion_r333415220
########## File path: be/src/exprs/aggregate_functions.cpp ########## @@ -305,6 +250,59 @@ DoubleVal AggregateFunctions::percentile_approx_finalize(FunctionContext* ctx, c return DoubleVal(result); } +struct AvgState { + double sum = 0; + int64_t count = 0; +}; + +struct DecimalAvgState { + DecimalVal sum; + int64_t count; +}; + +struct DecimalV2AvgState { + DecimalV2Val sum; + int64_t count = 0; +}; + +void AggregateFunctions::avg_init(FunctionContext* ctx, StringVal* dst) { + dst->is_null = false; + dst->len = sizeof(AvgState); + dst->ptr = ctx->allocate(dst->len); + dst->ptr = (uint8_t*) new (dst->ptr) AvgState; Review comment: ```suggestion new (dst->ptr) AvgState; ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org