|
22 | 22 | #include "optimizer/properties.h"
|
23 | 23 | #include "optimizer/optimizer_metadata.h"
|
24 | 24 |
|
| 25 | + |
25 | 26 | namespace peloton {
|
26 | 27 | namespace optimizer {
|
27 | 28 |
|
@@ -97,20 +98,59 @@ void InnerJoinAssociativity::Transform(
|
97 | 98 | std::shared_ptr<OperatorExpression> input,
|
98 | 99 | std::vector<std::shared_ptr<OperatorExpression>> &transformed,
|
99 | 100 | UNUSED_ATTRIBUTE OptimizeContext *context) const {
|
100 |
| - auto join_op = input->Op().As<LogicalInnerJoin>(); |
101 |
| - auto join_predicates = |
102 |
| - std::vector<AnnotatedExpression>(join_op->join_predicates); |
103 |
| - auto result_plan = std::make_shared<OperatorExpression>( |
104 |
| - LogicalInnerJoin::make(join_predicates)); |
| 101 | + |
| 102 | + |
| 103 | + // NOTE: Transforms (left JOIN middle) JOIN right -> left JOIN (middle JOIN right) |
| 104 | + // Variables are named accordingly to above transformation |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +// auto result_plan = std::make_shared<OperatorExpression>( |
| 109 | +// LogicalInnerJoin::make(join_predicates)); |
| 110 | + |
| 111 | + auto parent_join = input->Op().As<LogicalInnerJoin>(); |
105 | 112 | std::vector<std::shared_ptr<OperatorExpression>> children = input->Children();
|
| 113 | + auto child_join = children[0]->Op().As<LogicalInnerJoin>(); |
106 | 114 | PL_ASSERT(children.size() == 2);
|
107 |
| - LOG_TRACE( |
108 |
| - "Reorder left child with op %s and right child with op %s for inner join", |
109 |
| - children[0]->Op().GetName().c_str(), children[1]->Op().GetName().c_str()); |
110 |
| - result_plan->PushChild(children[1]); |
111 |
| - result_plan->PushChild(children[0]); |
| 115 | + PL_ASSERT(children[0]->Op().GetType() == OpType::InnerJoin); |
| 116 | + PL_ASSERT(children[0]->Children().size() == 2); |
112 | 117 |
|
113 |
| - transformed.push_back(result_plan); |
| 118 | + // Get Alias sets |
| 119 | + auto &memo = context->metadata->memo; |
| 120 | + auto left_group_id = children[0]->Children()[0]->Op().As<LeafOperator>()->origin_group; |
| 121 | + auto middle_group_id = children[0]->Children()[1]->Op().As<LeafOperator>()->origin_group; |
| 122 | + auto right_group_id = children[1]->Op().As<LeafOperator>()->origin_group; |
| 123 | + |
| 124 | + const auto &left_group_aliases_set = |
| 125 | + memo.GetGroupByID(left_group_id)->GetTableAliases(); |
| 126 | + const auto &middle_group_aliases_set = |
| 127 | + memo.GetGroupByID(middle_group_id)->GetTableAliases(); |
| 128 | + const auto &right_group_aliases_set = |
| 129 | + memo.GetGroupByID(right_group_id)->GetTableAliases(); |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + // Redistribute predicates |
| 134 | + auto parent_join_predicates = std::vector<AnnotatedExpression>(parent_join->join_predicates); |
| 135 | + auto child_join_predicates = std::vector<AnnotatedExpression>(child_join->join_predicates); |
| 136 | + |
| 137 | + std::vector<AnnotatedExpression> predicates; |
| 138 | + predicates.insert(predicates.end(), parent_join_predicates.begin(), parent_join_predicates.end()); |
| 139 | + predicates.insert(predicates.end(), child_join_predicates.begin(), child_join_predicates.end()); |
| 140 | + |
| 141 | +// for (auto predicate : predicates) { |
| 142 | +// |
| 143 | +// } |
| 144 | +// |
| 145 | +// |
| 146 | +// |
| 147 | +// LOG_TRACE( |
| 148 | +// "Reorder left child with op %s and right child with op %s for inner join", |
| 149 | +// children[0]->Op().GetName().c_str(), children[1]->Op().GetName().c_str()); |
| 150 | +// result_plan->PushChild(children[1]); |
| 151 | +// result_plan->PushChild(children[0]); |
| 152 | +// |
| 153 | +// transformed.push_back(result_plan); |
114 | 154 | }
|
115 | 155 |
|
116 | 156 | //===--------------------------------------------------------------------===//
|
|
0 commit comments