mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
PhysicalPlanTable.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
8#include <vector>
9
10
11namespace m {
12
13// forward declarations
14struct MatchBase;
15
16namespace detail {
17
19template<typename Entry>
21{
23 Entry entry;
24
26 : condition(std::move(condition)), entry(std::move(entry))
27 { }
28
30 condition_entry_t(condition_entry_t&&) = default; // to make it move-insertable
32};
33
40template<typename Actual, bool C, typename Entry>
41struct the_condition_entry_iterator : crtp_boolean<Actual, the_condition_entry_iterator, C, Entry>
42{
44 using entry_type = Entry;
45 static constexpr bool IsConst = C; // Actual::IsConst not possible since this abstract class is initialized first
46
48 using reference = std::conditional_t<IsConst, const value_type&, value_type&>;
49 using pointer = std::conditional_t<IsConst, const value_type*, value_type*>;
50
51 bool operator==(const the_condition_entry_iterator &other) const {
52 return actual().operator==(other);
53 }
54 bool operator!=(const the_condition_entry_iterator &other) const {
55 return actual().operator!=(other);
56 }
57
58 the_condition_entry_iterator & operator++() { return actual().operator++(); }
59 the_condition_entry_iterator operator++(int) { return actual().operator++(int{}); }
60
61 reference operator*() const { return actual().operator*(); }
62 pointer operator->() const { return actual().operator->(); }
63};
64
66template<template<bool> typename Actual, bool C, typename Entry>
68
69}
70
75template<typename Actual, template<bool> typename ChildIt>
76requires requires {
78}
79struct PhysicalPlanTableEntry : crtp_boolean_templated<Actual, PhysicalPlanTableEntry, ChildIt>
80{
82 template<bool C> using child_iterator_type = ChildIt<C>;
84 using cost_type = double;
85
86 template<typename It>
87 requires requires { typename detail::the_condition_entry_iterator<It, true, Actual>; }
88 PhysicalPlanTableEntry(std::unique_ptr<MatchBase> &&match, const std::vector<It> &children, cost_type cost)
89 : Actual::Actual(std::move(match), children, cost)
90 { }
91
94 PhysicalPlanTableEntry(PhysicalPlanTableEntry &&other) : Actual::Actual(as<Actual>(std::move(other))) { }
95
97 this->actual() = as<Actual>(std::move(other));
98 return *this;
99 }
100
101 const MatchBase & match() const { return actual().match(); }
103 unsharable_shared_ptr<MatchBase> share_match() const { return actual().share_match(); }
106
107 cost_type cost() const { return actual.cost(); }
108
109 const_child_iterator begin_children() const { return actual().begin_children(); }
110 const_child_iterator end_children() const { return actual().end_children(); }
111 const_child_iterator cbegin_children() const { return actual().cbegin_children(); }
112 const_child_iterator cend_children() const { return actual().cend_children(); }
113
115};
116
120template<typename Actual, template<bool> typename It, typename Entry>
121requires requires {
122 typename PhysicalPlanTableEntry<Entry, Entry::template child_iterator_type>;
123 typename detail::the_condition_entry_templated_iterator<It, false, Entry>;
124 typename detail::the_condition_entry_templated_iterator<It, true, Entry>;
125}
127 : crtp_boolean_templated<Actual, Condition2PPTEntryMap, It, Entry>
128{
130 template<bool C> using iterator_type = It<C>;
133 using entry_type = Entry;
134
138 : Actual::Actual(as<Actual>(std::move(other)))
139 { }
140
142 this->actual() = as<Actual>(std::move(other));
143 return *this;
144 }
145
146 bool empty() const { return actual().empty(); }
147
148 void insert(ConditionSet &&condition, entry_type &&entry) {
149 return actual().insert(std::move(condition), std::move(entry));
150 }
151
152 iterator begin() { return actual().begin(); }
153 iterator end() { return actual().end(); }
154 const_iterator begin() const { return actual().begin(); }
155 const_iterator end() const { return actual().end(); }
156 const_iterator cbegin() const { return actual().cbegin(); }
157 const_iterator cend() const { return actual().cend(); }
158};
159
162template<typename Actual, typename Condition2EntryMap>
163requires requires {
164 typename Condition2PPTEntryMap<
165 Condition2EntryMap, Condition2EntryMap::template iterator_type, typename Condition2EntryMap::entry_type
166 >;
167}
168struct PhysicalPlanTable : crtp<Actual, PhysicalPlanTable, Condition2EntryMap>
169{
170 using crtp<Actual, PhysicalPlanTable, Condition2EntryMap>::actual;
171 using size_type = std::size_t;
172 using condition2entry_map_type = Condition2EntryMap;
173
174 PhysicalPlanTable() = default;
176 PhysicalPlanTable(PhysicalPlanTable &&other) : Actual::Actual(as<Actual>(std::move(other))) { }
177
179 this->actual() = as<Actual>(std::move(other));
180 return *this;
181 }
182
183 void clear() { actual().clear(); }
184 size_type size() const { return actual().size(); }
185 void resize(size_type size) { actual().resize(size); }
186
187 condition2entry_map_type & operator[](size_type idx) { return actual().operator[](idx); }
189 return actual().operator[](idx);
190 }
191
192 condition2entry_map_type & back() { return actual().back(); }
193 const condition2entry_map_type & back() const { return actual().back(); }
194};
195
196}
Check whether.
Definition: concepts.hpp:39
‍mutable namespace
Definition: Backend.hpp:10
STL namespace.
Interface for a mapping between ConditionSets and physical plan table entries of type.
Condition2PPTEntryMap(Condition2PPTEntryMap &&other)
iterator_type< false > iterator
const_iterator cend() const
Condition2PPTEntryMap & operator=(Condition2PPTEntryMap other)
iterator_type< true > const_iterator
const_iterator end() const
void insert(ConditionSet &&condition, entry_type &&entry)
const_iterator cbegin() const
const_iterator begin() const
Condition2PPTEntryMap(const Condition2PPTEntryMap &)=delete
Interface for a single physical plan table entry.
range< const_child_iterator > children() const
const_child_iterator cbegin_children() const
unsharable_shared_ptr< MatchBase > extract_match()
Extracts the found match by moving it out of this.
unsharable_shared_ptr< MatchBase > share_match() const
Shares the found match.
const MatchBase & match() const
PhysicalPlanTableEntry(PhysicalPlanTableEntry &&other)
child_iterator_type< true > const_child_iterator
PhysicalPlanTableEntry(const PhysicalPlanTableEntry &)=delete
PhysicalPlanTableEntry & operator=(PhysicalPlanTableEntry other)
const_child_iterator end_children() const
const_child_iterator begin_children() const
PhysicalPlanTableEntry(std::unique_ptr< MatchBase > &&match, const std::vector< It > &children, cost_type cost)
const_child_iterator cend_children() const
Interface for an entire physical plan table containing a ConditionSet-entry-mapping.
condition2entry_map_type & operator[](size_type idx)
void resize(size_type size)
condition2entry_map_type & back()
PhysicalPlanTable()=default
Condition2EntryMap condition2entry_map_type
const condition2entry_map_type & back() const
size_type size() const
PhysicalPlanTable(PhysicalPlanTable &&other)
PhysicalPlanTable(const PhysicalPlanTable &)=delete
PhysicalPlanTable & operator=(PhysicalPlanTable other)
const condition2entry_map_type & operator[](size_type idx) const
A helper class to define CRTP class hierarchies with an additional boolean template template paramete...
Definition: crtp.hpp:80
A helper class to define CRTP class hierarchies with an additional boolean template parameter (this i...
Definition: crtp.hpp:65
A helper class to define CRTP class hierarchies.
Definition: crtp.hpp:50
Helper struct to unite ConditionSets and entries of type.
condition_entry_t(condition_entry_t &&)=default
condition_entry_t()=delete
Entry entry
condition_entry_t(ConditionSet &&condition, Entry &&entry)
ConditionSet condition
condition_entry_t & operator=(condition_entry_t &&)=delete
Iterator interface to iterate over pairs of ConditionSet and.
Entry entry_type
bool operator!=(const the_condition_entry_iterator &other) const
static constexpr bool IsConst
std::conditional_t< IsConst, const value_type &, value_type & > reference
the_condition_entry_iterator operator++(int)
reference operator*() const
pointer operator->() const
the_condition_entry_iterator & operator++()
bool operator==(const the_condition_entry_iterator &other) const
Helper struct for templated iterators.
This class extends std::shared_ptr to allow for unsharing an exclusively held object and thereby conv...