From dbff1edcd34ff05ecf657b50f3164e06ded73a81 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 14 Jun 2021 05:26:05 +0300 Subject: [PATCH] Fix memory tracking of aggregate function topK --- src/AggregateFunctions/AggregateFunctionTopK.h | 3 ++- src/Common/SpaceSaving.h | 5 +++-- .../queries/0_stateless/01910_memory_tracking_topk.reference | 0 tests/queries/0_stateless/01910_memory_tracking_topk.sql | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/01910_memory_tracking_topk.reference create mode 100644 tests/queries/0_stateless/01910_memory_tracking_topk.sql diff --git a/src/AggregateFunctions/AggregateFunctionTopK.h b/src/AggregateFunctions/AggregateFunctionTopK.h index 30d69b8ca7b..1988b1f8b2a 100644 --- a/src/AggregateFunctions/AggregateFunctionTopK.h +++ b/src/AggregateFunctions/AggregateFunctionTopK.h @@ -118,7 +118,8 @@ struct AggregateFunctionTopKGenericData * For such columns topK() can be implemented more efficiently (especially for small numeric arrays). */ template -class AggregateFunctionTopKGeneric : public IAggregateFunctionDataHelper> +class AggregateFunctionTopKGeneric + : public IAggregateFunctionDataHelper> { private: using State = AggregateFunctionTopKGenericData; diff --git a/src/Common/SpaceSaving.h b/src/Common/SpaceSaving.h index b7353d803b7..d1e6d079d17 100644 --- a/src/Common/SpaceSaving.h +++ b/src/Common/SpaceSaving.h @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -382,8 +383,8 @@ private: using CounterMap = HashMapWithStackMemory; CounterMap counter_map; - std::vector counter_list; - std::vector alpha_map; + std::vector> counter_list; + std::vector> alpha_map; SpaceSavingArena arena; size_t m_capacity; size_t removed_keys = 0; diff --git a/tests/queries/0_stateless/01910_memory_tracking_topk.reference b/tests/queries/0_stateless/01910_memory_tracking_topk.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01910_memory_tracking_topk.sql b/tests/queries/0_stateless/01910_memory_tracking_topk.sql new file mode 100644 index 00000000000..e6309c1eeb8 --- /dev/null +++ b/tests/queries/0_stateless/01910_memory_tracking_topk.sql @@ -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 }