Fix memory tracking of aggregate function topK

This commit is contained in:
Alexey Milovidov 2021-06-14 05:26:05 +03:00
parent 39515083e4
commit dbff1edcd3
4 changed files with 9 additions and 3 deletions

View File

@ -118,7 +118,8 @@ struct AggregateFunctionTopKGenericData
* For such columns topK() can be implemented more efficiently (especially for small numeric arrays). * For such columns topK() can be implemented more efficiently (especially for small numeric arrays).
*/ */
template <bool is_plain_column, bool is_weighted> template <bool is_plain_column, bool is_weighted>
class AggregateFunctionTopKGeneric : public IAggregateFunctionDataHelper<AggregateFunctionTopKGenericData, AggregateFunctionTopKGeneric<is_plain_column, is_weighted>> class AggregateFunctionTopKGeneric
: public IAggregateFunctionDataHelper<AggregateFunctionTopKGenericData, AggregateFunctionTopKGeneric<is_plain_column, is_weighted>>
{ {
private: private:
using State = AggregateFunctionTopKGenericData; using State = AggregateFunctionTopKGenericData;

View File

@ -5,6 +5,7 @@
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <Common/AllocatorWithMemoryTracking.h>
#include <Common/ArenaWithFreeLists.h> #include <Common/ArenaWithFreeLists.h>
#include <Common/HashTable/Hash.h> #include <Common/HashTable/Hash.h>
#include <Common/HashTable/HashMap.h> #include <Common/HashTable/HashMap.h>
@ -382,8 +383,8 @@ private:
using CounterMap = HashMapWithStackMemory<TKey, Counter *, Hash, 4>; using CounterMap = HashMapWithStackMemory<TKey, Counter *, Hash, 4>;
CounterMap counter_map; CounterMap counter_map;
std::vector<Counter *> counter_list; std::vector<Counter *, AllocatorWithMemoryTracking<Counter *>> counter_list;
std::vector<UInt64> alpha_map; std::vector<UInt64, AllocatorWithMemoryTracking<UInt64>> alpha_map;
SpaceSavingArena<TKey> arena; SpaceSavingArena<TKey> arena;
size_t m_capacity; size_t m_capacity;
size_t removed_keys = 0; size_t removed_keys = 0;

View File

@ -0,0 +1,4 @@
-- Memory limit must correctly apply, triggering an exception:
SET max_memory_usage = '100M';
SELECT length(topK(5592405)(tuple(number))) FROM numbers(10) GROUP BY number; -- { serverError 241 }