mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
ColumnStore.cpp
Go to the documentation of this file.
2
5#include <numeric>
6
7
8using namespace m;
9
10
12 : Store(table)
13{
14 uint64_t max_attr_size = 0;
15
16 /* Allocate memory for the attributes columns and the null bitmap column. */
18
19 /* Compute the capacity depending on the column with the largest attribute size. */
20 for (auto attr = table.begin_all(); attr != table.end_all(); ++attr) {
21 auto size = attr->type->size();
22 row_size_ += size;
23 max_attr_size = std::max(max_attr_size, size);
24 }
25 uint32_t num_attrs = table.num_attrs();
26 row_size_ += num_attrs;
27 uint64_t null_bitmap_size = /* pad_null_bitmap= */ 1 ? ((num_attrs + 7) / 8) * 8 : num_attrs;
28 max_attr_size = std::max(max_attr_size, null_bitmap_size);
29
30 capacity_ = (ALLOCATION_SIZE * 8) / max_attr_size;
31}
32
34
36void ColumnStore::dump(std::ostream &out) const
37{
38 out << "ColumnStore for table \"" << table().name() << "\": " << num_rows_ << '/' << capacity_
39 << " rows, " << row_size_ << " bits per row" << std::endl;
40}
42
43__attribute__((constructor(202)))
44static void register_store()
45{
46 Catalog &C = Catalog::Get();
47 C.register_store<ColumnStore>(C.pool("ColumnStore"), "stores attributes in column-major order");
48}
__attribute__((constructor(202))) static void register_interpreter()
‍mutable namespace
Definition: Backend.hpp:10
The catalog contains all Databases and keeps track of all meta information of the database system.
Definition: Catalog.hpp:215
ThreadSafePooledString pool(const char *str) const
Creates an internalized copy of the string str by adding it to the internal StringPool.
Definition: Catalog.hpp:274
static Catalog & Get()
Return a reference to the single Catalog instance.
void register_store(ThreadSafePooledString name, const char *description=nullptr)
Registers a new Store with the given name.
Definition: Catalog.hpp:343
This class implements a column store.
Definition: ColumnStore.hpp:12
void dump() const
Definition: Store.cpp:14
static constexpr std::size_t ALLOCATION_SIZE
1 GiB
Definition: ColumnStore.hpp:14
ColumnStore(const Table &table)
Definition: ColumnStore.cpp:11
std::size_t capacity_
Definition: ColumnStore.hpp:23
std::size_t num_rows_
Definition: ColumnStore.hpp:22
memory::Memory data_
Definition: ColumnStore.hpp:21
std::size_t row_size_
Definition: ColumnStore.hpp:24
memory::LinearAllocator allocator_
the memory allocator
Definition: ColumnStore.hpp:20
Defines a generic store interface.
Definition: Store.hpp:22
const Table & table() const
Definition: Store.hpp:36
A table is a sorted set of attributes.
Definition: Schema.hpp:388
virtual all_iterator begin_all() const =0
virtual const ThreadSafePooledString & name() const =0
Returns the name of the Table.
virtual all_iterator end_all() const =0
virtual std::size_t num_attrs() const =0
Returns the number of attributes in this table.
Memory allocate(std::size_t size) override
Creates a new memory object with size bytes of freshly allocated memory.
Definition: memory.cpp:120
std::size_t size() const
Returns the size in bytes of this allocation.
Definition: memory.hpp:111