Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 361e8c4

Browse files
author
GustavoAngulo
committed
Extracted predicates, need to implement predicate redistribution
1 parent 2070980 commit 361e8c4

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

src/include/optimizer/rule_impls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "optimizer/rule.h"
1616

1717
#include <memory>
18+
#include <algorithm>
19+
1820

1921
namespace peloton {
2022
namespace optimizer {

src/optimizer/rule_impls.cpp

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "optimizer/properties.h"
2323
#include "optimizer/optimizer_metadata.h"
2424

25+
2526
namespace peloton {
2627
namespace optimizer {
2728

@@ -97,20 +98,59 @@ void InnerJoinAssociativity::Transform(
9798
std::shared_ptr<OperatorExpression> input,
9899
std::vector<std::shared_ptr<OperatorExpression>> &transformed,
99100
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>();
105112
std::vector<std::shared_ptr<OperatorExpression>> children = input->Children();
113+
auto child_join = children[0]->Op().As<LogicalInnerJoin>();
106114
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);
112117

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);
114154
}
115155

116156
//===--------------------------------------------------------------------===//

0 commit comments

Comments
 (0)