From 16333e9f3a7cca295ac5156ec1eef318adbb6f05 Mon Sep 17 00:00:00 2001 From: hexiaoting Date: Mon, 1 Mar 2021 18:04:34 +0800 Subject: [PATCH 001/325] Suppport fuse aggregate functions:sum/avg/count to sumCount --- .../AggregateFunctionSumCount.cpp | 59 ++++ .../AggregateFunctionSumCount.h | 281 ++++++++++++++++++ .../registerAggregateFunctions.cpp | 2 + src/Core/Settings.h | 1 + src/Interpreters/GetAggregatesVisitor.h | 9 + src/Interpreters/TreeRewriter.cpp | 65 ++++ .../01744_fuse_sum_count_aggregate.reference | 6 + .../01744_fuse_sum_count_aggregate.sql | 8 + 8 files changed, 431 insertions(+) create mode 100644 src/AggregateFunctions/AggregateFunctionSumCount.cpp create mode 100644 src/AggregateFunctions/AggregateFunctionSumCount.h create mode 100644 tests/queries/0_stateless/01744_fuse_sum_count_aggregate.reference create mode 100644 tests/queries/0_stateless/01744_fuse_sum_count_aggregate.sql diff --git a/src/AggregateFunctions/AggregateFunctionSumCount.cpp b/src/AggregateFunctions/AggregateFunctionSumCount.cpp new file mode 100644 index 00000000000..48770b629a8 --- /dev/null +++ b/src/AggregateFunctions/AggregateFunctionSumCount.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include "registerAggregateFunctions.h" + + +namespace DB +{ +namespace ErrorCodes +{ + extern const int ILLEGAL_TYPE_OF_ARGUMENT; +} + +namespace +{ + +template +struct SumSimple +{ + /// @note It uses slow Decimal128 (cause we need such a variant). sumWithOverflow is faster for Decimal32/64 + using ResultType = std::conditional_t, + std::conditional_t, Decimal256, Decimal128>, + NearestFieldType>; + using AggregateDataType = AggregateFunctionSumCountData; + using Function = AggregateFunctionSumCount; +}; + + + +template using AggregateFunctionSumCountSimple = typename SumSimple::Function; + +template