diff --git a/src/AggregateFunctions/AggregateFunctionForEach.h b/src/AggregateFunctions/AggregateFunctionForEach.h index becd00a782e..07713dcb304 100644 --- a/src/AggregateFunctions/AggregateFunctionForEach.h +++ b/src/AggregateFunctions/AggregateFunctionForEach.h @@ -145,7 +145,7 @@ public: return nested_func->getDefaultVersion(); } - template + template void destroyImpl(AggregateDataPtr __restrict place) const noexcept { AggregateFunctionForEachData & state = data(place); @@ -153,7 +153,7 @@ public: char * nested_state = state.array_of_aggregate_datas; for (size_t i = 0; i < state.dynamic_array_size; ++i) { - if constexpr (up_tp_state) + if constexpr (up_to_state) nested_func->destroyUpToState(nested_state); else nested_func->destroy(nested_state); diff --git a/src/AggregateFunctions/AggregateFunctionMap.h b/src/AggregateFunctions/AggregateFunctionMap.h index 3eb2599a0d4..527f35fd948 100644 --- a/src/AggregateFunctions/AggregateFunctionMap.h +++ b/src/AggregateFunctions/AggregateFunctionMap.h @@ -225,8 +225,7 @@ public: nested_func->destroy(nested_place); } - auto to_destroy = std::move(state.merged_maps); - this->data(place).~Data(); + state.~Data(); } void destroy(AggregateDataPtr __restrict place) const noexcept override diff --git a/src/Interpreters/Aggregator.cpp b/src/Interpreters/Aggregator.cpp index 0eb6ce7afad..2080f36a531 100644 --- a/src/Interpreters/Aggregator.cpp +++ b/src/Interpreters/Aggregator.cpp @@ -1756,6 +1756,9 @@ inline void Aggregator::insertAggregatesIntoColumns(Mapped & mapped, MutableColu * and ColumnAggregateFunction will take ownership of this state. * So, for aggregate functions with "-State" modifier, only states of all combinators that are used * after -State will be destroyed after result has been transferred to ColumnAggregateFunction. + * For example, if we have function `uniqStateForEachMap` after aggregation we should destroy all states that + * were created by combinators `-ForEach` and `-Map`, because resulting ColumnAggregateFunction will be + * responsible only for destruction of the states created by `uniq` function. * But we should mark that the data no longer owns these states. */