Branch data Line data Source code
1 : : #pragma once 2 : : 3 : : #include <mutable/catalog/Schema.hpp> 4 : : #include <mutable/storage/Store.hpp> 5 : : #include <mutable/util/memory.hpp> 6 : : 7 : : 8 : : namespace m { 9 : : 10 : : /** This class implements a generic PAX store. */ 11 : : struct PaxStore : Store 12 : : { 13 : : #ifndef NDEBUG 14 : : static constexpr std::size_t ALLOCATION_SIZE = 1UL << 30; ///< 1 GiB 15 : : #else 16 : : static constexpr std::size_t ALLOCATION_SIZE = 1UL << 37; ///< 128 GiB 17 : : #endif 18 : : 19 : : static constexpr uint32_t BLOCK_SIZE = 1UL << 12; ///< 4 KiB 20 : : 21 : : private: 22 : : memory::LinearAllocator allocator_; ///< the memory allocator 23 : : memory::Memory data_; ///< the underlying memory containing the data 24 : : std::size_t num_rows_ = 0; ///< the number of rows in use 25 : : std::size_t capacity_; ///< the number of available rows 26 : : uint32_t *offsets_; ///< the offsets of each column within a PAX block, in bits 27 : : uint32_t block_size_; ///< the size of a PAX block, in bytes; includes padding 28 : : std::size_t num_rows_per_block_; ///< the number of rows within a PAX block 29 : : 30 : : public: 31 : : PaxStore(const Table &table, uint32_t block_size_in_bytes = BLOCK_SIZE); 32 : : ~PaxStore(); 33 : : 34 : 393387 : virtual std::size_t num_rows() const override { return num_rows_; } 35 : 2 : std::size_t num_rows_per_block() const { return num_rows_per_block_; } 36 : : uint32_t block_size() const { return block_size_; } 37 : : 38 : 10 : uint32_t offset(uint32_t idx) const { 39 : 10 : M_insist(idx <= table().num_attrs(), "index out of range"); 40 : 10 : return offsets_[idx]; 41 : : } 42 : 10 : uint32_t offset(const Attribute &attr) const { return offset(attr.id); } 43 : : 44 : 398977 : void append() override { 45 [ + + ]: 398977 : if (num_rows_ == capacity_) 46 [ + - ]: 1 : throw std::logic_error("row store exceeds capacity"); 47 : 398976 : ++num_rows_; 48 : 398976 : } 49 : : 50 : 2 : void drop() override { 51 : 2 : M_insist(num_rows_); 52 : 2 : --num_rows_; 53 : 2 : } 54 : : 55 : : /** Returns the memory of the store. */ 56 : 82 : const memory::Memory & memory() const override { return data_; } 57 : : 58 : : void dump(std::ostream &out) const override; 59 : : using Store::dump; 60 : : 61 : : private: 62 : : /** Computes the offsets of the columns within a PAX block, the rows size, the number of rows that fit in a PAX 63 : : * block, and the capacity. Tries to maximize the number of rows within a PAX block by storing the attributes in 64 : : * descending order of their size, avoiding padding. */ 65 : : void compute_block_offsets(); 66 : : }; 67 : : 68 : : }