9template<
typename PlanTable>
12 if (PT.num_sources() == 0)
15 if (PT.num_sources() == 1) {
18 callback(partial_plans);
22 const auto &final_plan_entry = PT.get_final();
23 const Subproblem root_of_final_plan = final_plan_entry.left | final_plan_entry.right;
30 std::vector<bool> decision_stack;
31 partial_plans.reserve(PT.num_sources());
32 candidates.reserve(PT.num_sources());
35 decision_stack.reserve(2 * PT.num_sources());
38 partial_plans.emplace_back(root_of_final_plan);
39 decision_stack.emplace_back(
true);
42 if (candidates.empty()) {
43 callback(partial_plans);
47 if (decision_stack.empty())
50 const bool was_partial_plan_taken = decision_stack.back();
51 if (not was_partial_plan_taken) {
54 candidates.pop_back();
56 candidates.pop_back();
57 decision_stack.pop_back();
58 candidates.emplace_back(left|right);
63 const auto partial_plan = partial_plans.back();
64 partial_plans.pop_back();
65 if (partial_plan.is_singleton()) {
66 decision_stack.pop_back();
67 candidates.push_back(partial_plan);
72 decision_stack.back() =
false;
73 candidates.push_back(PT[partial_plan].left);
74 candidates.push_back(PT[partial_plan].right);
79 auto partial_plan = candidates.back();
80 candidates.pop_back();
81 partial_plans.emplace_back(partial_plan);
82 decision_stack.emplace_back(
true);
88template<
typename PlanTable>
93 auto write_tree = [&](
Subproblem root) ->
void {
94 auto write_tree_rec = [&](
Subproblem root,
auto &write_tree_rec) ->
void {
99 write_tree_rec(PT[root].left, write_tree_rec);
101 write_tree_rec(PT[root].right, write_tree_rec);
104 write_tree_rec(root, write_tree_rec);
122 M_insist(not partial_plans.empty());
124 static bool is_first =
true;
132 for (
auto it = partial_plans.cbegin(); it != partial_plans.cend(); ++it) {
133 if (it != partial_plans.cbegin()) out <<
", ";
146 for_each_partial_plan(write_partial_plan);
void for_each_complete_partial_plan(const PlanTable &PT, callback_type callback)
Given a PlanTable with a final plan, enumerate all complete partial plans of this final plan and invo...
void write_partial_plans_JSON(std::ostream &out, const QueryGraph &G, const PlanTable &PT, std::function< void(callback_type)> for_each_partial_plan)
std::vector< Subproblem > partial_plan_type
std::function< void(const partial_plan_type &)> callback_type
This table represents all explored plans with their sub-plans, estimated size, cost,...
This table represents all explored plans with their sub-plans, estimated size, cost,...
The query graph represents all data sources and joins in a graph structure.
const auto & sources() const
Implements a small and efficient set over integers in the range of 0 to 63 (including).
bool is_singleton() const