diff --git a/dbms/include/DB/Columns/ColumnAggregateFunction.h b/dbms/include/DB/Columns/ColumnAggregateFunction.h index e5bd2d340e1..0c6f881906e 100644 --- a/dbms/include/DB/Columns/ColumnAggregateFunction.h +++ b/dbms/include/DB/Columns/ColumnAggregateFunction.h @@ -21,9 +21,6 @@ namespace DB class ColumnAggregateFunction : public ColumnVectorBase { private: - typedef SharedPtr ArenaPtr; - typedef std::vector Arenas; - AggregateFunctionPtr func; Arenas arenas; public: diff --git a/dbms/include/DB/Common/Arena.h b/dbms/include/DB/Common/Arena.h index db8772dbe54..9bbb3bca5e1 100644 --- a/dbms/include/DB/Common/Arena.h +++ b/dbms/include/DB/Common/Arena.h @@ -2,6 +2,8 @@ #include #include +#include +#include #include @@ -92,5 +94,8 @@ public: } }; +typedef Poco::SharedPtr ArenaPtr; +typedef std::vector Arenas; + } diff --git a/dbms/include/DB/Interpreters/Aggregator.h b/dbms/include/DB/Interpreters/Aggregator.h index 720bb800609..3db64abe6f2 100644 --- a/dbms/include/DB/Interpreters/Aggregator.h +++ b/dbms/include/DB/Interpreters/Aggregator.h @@ -49,8 +49,9 @@ typedef HashMap, UInt128Hash, UInt128Z struct AggregatedDataVariants { - /// Пул для состояний агрегатных функций. Владение потом будет передано в ColumnAggregateFunction. - SharedPtr aggregates_pool; + /// Пулы для состояний агрегатных функций. Владение потом будет передано в ColumnAggregateFunction. + Arenas aggregates_pools; + Arena * aggregates_pool; /// Последний пул, который используется для аллокации. /// Наиболее общий вариант. Самый медленный. На данный момент, не используется. AggregatedData generic; @@ -83,7 +84,7 @@ struct AggregatedDataVariants }; Type type; - AggregatedDataVariants() : aggregates_pool(new Arena), without_key(NULL), type(EMPTY) {} + AggregatedDataVariants() : aggregates_pools(1, new Arena), aggregates_pool(&*aggregates_pools.back()), without_key(NULL), type(EMPTY) {} bool empty() const { return type == EMPTY; } size_t size() const diff --git a/dbms/src/Interpreters/Aggregator.cpp b/dbms/src/Interpreters/Aggregator.cpp index d02c12edcb3..45237abe12e 100644 --- a/dbms/src/Interpreters/Aggregator.cpp +++ b/dbms/src/Interpreters/Aggregator.cpp @@ -478,7 +478,9 @@ Block Aggregator::convertToBlock(AggregatedDataVariants & data_variants) { /// Столбец ColumnAggregateFunction захватывает разделяемое владение ареной с состояниями агрегатных функций. ColumnAggregateFunction & column_aggregate_func = static_cast(*res.getByPosition(i + keys_size).column); - column_aggregate_func.addArena(data_variants.aggregates_pool); + + for (size_t j = 0; j < data_variants.aggregates_pools.size(); ++j) + column_aggregate_func.addArena(data_variants.aggregates_pools[j]); aggregate_columns[i] = &column_aggregate_func.getData(); aggregate_columns[i]->resize(rows); @@ -590,6 +592,8 @@ AggregatedDataVariantsPtr Aggregator::merge(ManyAggregatedDataVariants & data_va rows += data_variants[i]->size(); AggregatedDataVariants & current = *data_variants[i]; + res->aggregates_pools.insert(res->aggregates_pools.end(), current.aggregates_pools.begin(), current.aggregates_pools.end()); + if (current.empty()) continue;