24 auto &DB = C.get_database_in_use();
25 auto &CE = DB.cardinality_estimator();
28 std::size_t
n = 1UL << num_sources;
32 const uint64_t size_len = std::max<uint64_t>(
33 entry.model ? std::ceil(std::log10(CE.predict_cardinality(*entry.model))) : 0,
36 const uint64_t cost_len = std::isinf(entry.cost)
38 : std::max<uint64_t>(std::ceil(std::log10(entry.cost)), 4);
39 const uint64_t sub_len = std::max<uint64_t>(num_sources, 5);
41 out << std::left <<
"Plan Table:\n"
42 << std::setw(num_sources) <<
"Sub" <<
" "
43 << std::setw(size_len) <<
"Size" <<
" "
44 << std::setw(cost_len) <<
"Cost" <<
" "
45 << std::setw(sub_len) <<
"Left" <<
" "
46 << std::setw(sub_len) <<
"Right" <<
'\n' << std::right;
48 for (std::size_t i = 1; i <
n; ++i) {
50 sub.print_fixed_length(out, num_sources);
54 out << std::setw(size_len) << CE.predict_cardinality(*PT.
at(sub).
model);
56 out << std::setw(size_len) <<
'-';
58 << std::setw(cost_len) << PT.
at(sub).
cost <<
" "
59 << std::setw(sub_len) << uint64_t(PT.
at(sub).
left) <<
" "
60 << std::setw(sub_len) << uint64_t(PT.
at(sub).
right) <<
'\n';
62 out << std::setw(size_len) <<
'-' <<
" "
63 << std::setw(cost_len) <<
'-' <<
" "
64 << std::setw(sub_len) <<
'-' <<
" "
65 << std::setw(sub_len) <<
'-' <<
'\n';
86 auto &DB = C.get_database_in_use();
87 auto &CE = DB.cardinality_estimator();
90 uint64_t n = 1UL << num_sources;
94 const uint64_t size_len = std::max<uint64_t>(
95 entry.model ? std::ceil(std::log10(CE.predict_cardinality(*entry.model))) : 0,
98 const uint64_t cost_len = std::max<uint64_t>(std::ceil(std::log10(entry.cost)), 4);
99 const uint64_t sub_len = std::max<uint64_t>(num_sources, 5);
101 out << std::left <<
"Plan Table:\n"
102 << std::setw(num_sources) <<
"Sub" <<
" "
103 << std::setw(size_len) <<
"Size" <<
" "
104 << std::setw(cost_len) <<
"Cost" <<
" "
105 << std::setw(sub_len) <<
"Left" <<
" "
106 << std::setw(sub_len) <<
"Right" <<
'\n' << std::right;
108 std::vector<std::pair<Subproblem, const PlanTableEntry*>> sorted_entries;
109 sorted_entries.reserve(PT.
table_.size());
111 for (
auto &e : PT.
table_) {
112 if (uint64_t(e.first) > n)
115 auto pos = std::upper_bound(sorted_entries.begin(), sorted_entries.end(), e.first,
116 [](
Subproblem s,
const std::pair<Subproblem, const PlanTableEntry*> &elem) {
117 return uint64_t(s) < uint64_t(elem.first);
119 sorted_entries.emplace(pos, e.first, &e.second);
122 for (
auto &elem : sorted_entries) {
124 sub.print_fixed_length(out, num_sources);
127 if (elem.second->model)
128 out << std::setw(size_len) << CE.predict_cardinality(*(elem.second->model));
130 out << std::setw(size_len) <<
'-';
132 << std::setw(cost_len) << elem.second->cost <<
" "
133 << std::setw(sub_len) << uint64_t(elem.second->left) <<
" "
134 << std::setw(sub_len) << uint64_t(elem.second->right) <<
'\n';
136 out << std::setw(size_len) <<
'-' <<
" "
137 << std::setw(cost_len) <<
'-' <<
" "
138 << std::setw(sub_len) <<
'-' <<
" "
139 << std::setw(sub_len) <<
'-' <<
'\n';
M_LCOV_EXCL_START std::ostream & operator<<(std::ostream &out, const PlanTableBase< Actual > &PT)
static Catalog & Get()
Return a reference to the single Catalog instance.
PlanTableEntry & get_final()
Returns the entry for the final plan, i.e.
double cost
the cost of the subproblem
Subproblem left
the left subproblem
std::unique_ptr< DataModel > model
the model of this subplan's result
Subproblem right
the right subproblem
This table represents all explored plans with their sub-plans, estimated size, cost,...
size_type num_sources() const
std::unordered_map< Subproblem, PlanTableEntry, SubproblemHash > table_
the PlanTableEntrys
bool has_plan(Subproblem s) const
This table represents all explored plans with their sub-plans, estimated size, cost,...
size_type num_sources() const
PlanTableEntry & at(Subproblem s)
bool has_plan(Subproblem s) const
Implements a small and efficient set over integers in the range of 0 to 63 (including).