1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/execution/perfect_aggregate_hashtable.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/execution/base_aggregate_hashtable.hpp"
12#include "duckdb/storage/arena_allocator.hpp"
13
14namespace duckdb {
15
16class PerfectAggregateHashTable : public BaseAggregateHashTable {
17public:
18 PerfectAggregateHashTable(ClientContext &context, Allocator &allocator, const vector<LogicalType> &group_types,
19 vector<LogicalType> payload_types_p, vector<AggregateObject> aggregate_objects,
20 vector<Value> group_minima, vector<idx_t> required_bits);
21 ~PerfectAggregateHashTable() override;
22
23public:
24 //! Add the given data to the HT
25 void AddChunk(DataChunk &groups, DataChunk &payload);
26
27 //! Combines the target perfect aggregate HT into this one
28 void Combine(PerfectAggregateHashTable &other);
29
30 //! Scan the HT starting from the scan_position
31 void Scan(idx_t &scan_position, DataChunk &result);
32
33protected:
34 Vector addresses;
35 //! The required bits per group
36 vector<idx_t> required_bits;
37 //! The total required bits for the HT (this determines the max capacity)
38 idx_t total_required_bits;
39 //! The total amount of groups
40 idx_t total_groups;
41 //! The tuple size
42 idx_t tuple_size;
43 //! The number of grouping columns
44 idx_t grouping_columns;
45
46 // The actual pointer to the data
47 data_ptr_t data;
48 //! The owned data of the HT
49 unsafe_unique_array<data_t> owned_data;
50 //! Information on whether or not a specific group has any entries
51 unsafe_unique_array<bool> group_is_set;
52
53 //! The minimum values for each of the group columns
54 vector<Value> group_minima;
55
56 //! Reused selection vector
57 SelectionVector sel;
58
59 //! The arena allocator used by the aggregates for their internal state
60 ArenaAllocator aggregate_allocator;
61
62private:
63 //! Destroy the perfect aggregate HT (called automatically by the destructor)
64 void Destroy();
65};
66
67} // namespace duckdb
68