Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory tracking of aggregate function topK #25260

Merged
merged 1 commit into from Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/AggregateFunctions/AggregateFunctionTopK.h
Expand Up @@ -118,7 +118,8 @@ struct AggregateFunctionTopKGenericData
* For such columns topK() can be implemented more efficiently (especially for small numeric arrays).
*/
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:
using State = AggregateFunctionTopKGenericData;
Expand Down
5 changes: 3 additions & 2 deletions src/Common/SpaceSaving.h
Expand Up @@ -5,6 +5,7 @@

#include <boost/range/adaptor/reversed.hpp>

#include <Common/AllocatorWithMemoryTracking.h>
#include <Common/ArenaWithFreeLists.h>
#include <Common/HashTable/Hash.h>
#include <Common/HashTable/HashMap.h>
Expand Down Expand Up @@ -382,8 +383,8 @@ class SpaceSaving
using CounterMap = HashMapWithStackMemory<TKey, Counter *, Hash, 4>;

CounterMap counter_map;
std::vector<Counter *> counter_list;
std::vector<UInt64> alpha_map;
std::vector<Counter *, AllocatorWithMemoryTracking<Counter *>> counter_list;
std::vector<UInt64, AllocatorWithMemoryTracking<UInt64>> alpha_map;
SpaceSavingArena<TKey> arena;
size_t m_capacity;
size_t removed_keys = 0;
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions 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 }