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

Commit 5614f73

Browse files
author
Erik Sargent
committed
Merge branch 'equiv-experimental' of https://github.com/17zhangw/peloton into erik_short_circuit
2 parents 1648780 + 6900cd8 commit 5614f73

File tree

9 files changed

+238
-35
lines changed

9 files changed

+238
-35
lines changed

src/include/common/internal_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,9 +1388,9 @@ enum class RuleType : uint32_t {
13881388
// Logical equivalent
13891389
EQUIV_AND,
13901390
EQUIV_OR,
1391+
EQUIV_COMPARE_EQUAL,
13911392

1392-
// Transitive column related rules
1393-
TRANSITIVE_SINGLE_DEPTH, // (A.B = x) AND (A.B = y)
1393+
TV_EQUALITY_WITH_TWO_CV, // (A.B = x) AND (A.B = y) where x/y are constant
13941394
TRANSITIVE_CLOSURE_CONSTANT, // (A.B = x) AND (A.B = C.D)
13951395

13961396
// Boolean short-circuit rules

src/include/optimizer/group.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ class Group : public Printable {
100100
// This is called in rewrite phase to erase the only logical expression in the
101101
// group
102102
inline void EraseLogicalExpression() {
103-
PELOTON_ASSERT(logical_expressions_.size() == 1);
103+
// During query rewriting (pre-optimizer), the rewriter can execute in a scenario
104+
// where a group can have multiple logical expressions (due to AND/OR/= equivalence).
105+
// TODO(): refine these assertions to distinguish between optimizer/rewrite stages
106+
PELOTON_ASSERT(logical_expressions_.size() >= 1);
104107
PELOTON_ASSERT(physical_expressions_.size() == 0);
105108
logical_expressions_.clear();
106109
}

src/include/optimizer/memo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ class Memo {
8383
// a new one, which reqires us to first remove the original gexpr from the
8484
// memo
8585
void EraseExpression(GroupID group_id) {
86-
auto gexpr = groups_[group_id]->GetLogicalExpression();
87-
group_expressions_.erase(gexpr);
86+
std::vector<std::shared_ptr<GroupExpression<Node,OperatorType,OperatorExpr>>> gexprs = groups_[group_id]->GetLogicalExpressions();
87+
for (auto gexpr : gexprs) {
88+
group_expressions_.erase(gexpr.get());
89+
}
90+
8891
groups_[group_id]->EraseLogicalExpression();
8992
}
9093

src/include/optimizer/rule_rewrite.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ class EquivalentTransform: public Rule<AbsExpr_Container,ExpressionType,AbsExpr_
5252
OptimizeContextTemplate *context) const override;
5353
};
5454

55-
class TransitiveSingleDepthTransform: public Rule<AbsExpr_Container,ExpressionType,AbsExpr_Expression> {
55+
class TVEqualityWithTwoCVTransform: public Rule<AbsExpr_Container,ExpressionType,AbsExpr_Expression> {
5656
public:
57-
TransitiveSingleDepthTransform();
57+
TVEqualityWithTwoCVTransform();
5858

5959
int Promise(GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const override;
6060
bool Check(std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const override;

src/optimizer/optimizer_task.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,13 @@ bool RewriteTask<Node,OperatorType,OperatorExpr>::OptimizeCurrentGroup(bool repl
459459
for (auto &r : valid_rules) {
460460
GroupExprBindingIterator<Node,OperatorType,OperatorExpr> iterator(this->GetMemo(), cur_group_expr,
461461
r.rule->GetMatchPattern());
462-
if (iterator.HasNext()) {
462+
// Keep trying to apply until we exhaust all the bindings.
463+
// This could possibly be sub-optimal since the first binding that results
464+
// in a transformation by a rule will be applied and become the group's
465+
// "new" rewritten expression.
466+
while (iterator.HasNext()) {
463467
// Binding succeeded to a given expression structure
464468
auto before = iterator.Next();
465-
PELOTON_ASSERT(!iterator.HasNext());
466469

467470
// Attempt to apply the transformation
468471
std::vector<std::shared_ptr<OperatorExpr>> after;

src/optimizer/rule.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ RuleSet<Operator,OperatorType,OperatorExpr>::RuleSet() {
5555

5656
template <>
5757
RuleSet<AbsExpr_Container,ExpressionType,AbsExpr_Expression>::RuleSet() {
58+
// Comparator Elimination related rules
5859
std::vector<std::pair<RuleType,ExpressionType>> comp_elim_pairs = {
5960
std::make_pair(RuleType::CONSTANT_COMPARE_EQUAL, ExpressionType::COMPARE_EQUAL),
6061
std::make_pair(RuleType::CONSTANT_COMPARE_NOTEQUAL, ExpressionType::COMPARE_NOTEQUAL),
@@ -71,17 +72,21 @@ RuleSet<AbsExpr_Container,ExpressionType,AbsExpr_Expression>::RuleSet() {
7172
);
7273
}
7374

74-
AddRewriteRule(
75-
RewriteRuleSetName::EQUIVALENT_TRANSFORM,
76-
new EquivalentTransform(RuleType::EQUIV_AND, ExpressionType::CONJUNCTION_AND)
77-
);
78-
79-
AddRewriteRule(
80-
RewriteRuleSetName::EQUIVALENT_TRANSFORM,
81-
new EquivalentTransform(RuleType::EQUIV_OR, ExpressionType::CONJUNCTION_OR)
82-
);
75+
// Equivalent Transform related rules (flip AND, OR, EQUAL)
76+
std::vector<std::pair<RuleType,ExpressionType>> equiv_pairs = {
77+
std::make_pair(RuleType::EQUIV_AND, ExpressionType::CONJUNCTION_AND),
78+
std::make_pair(RuleType::EQUIV_OR, ExpressionType::CONJUNCTION_OR),
79+
std::make_pair(RuleType::EQUIV_COMPARE_EQUAL, ExpressionType::COMPARE_EQUAL)
80+
};
81+
for (auto &pair : equiv_pairs) {
82+
AddRewriteRule(
83+
RewriteRuleSetName::EQUIVALENT_TRANSFORM,
84+
new EquivalentTransform(pair.first, pair.second)
85+
);
86+
}
8387

84-
AddRewriteRule(RewriteRuleSetName::TRANSITIVE_TRANSFORM, new TransitiveSingleDepthTransform());
88+
// Additional rules
89+
AddRewriteRule(RewriteRuleSetName::TRANSITIVE_TRANSFORM, new TVEqualityWithTwoCVTransform());
8590
AddRewriteRule(RewriteRuleSetName::TRANSITIVE_TRANSFORM, new TransitiveClosureConstantTransform());
8691

8792
AddRewriteRule(RewriteRuleSetName::BOOLEAN_SHORT_CIRCUIT, new AndShortCircuit());

src/optimizer/rule_rewrite.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ void EquivalentTransform::Transform(std::shared_ptr<AbsExpr_Expression> input,
177177
// Transitive-Transform related functions
178178
//
179179
// ===========================================================
180-
TransitiveSingleDepthTransform::TransitiveSingleDepthTransform() {
181-
type_ = RuleType::TRANSITIVE_SINGLE_DEPTH;
180+
TVEqualityWithTwoCVTransform::TVEqualityWithTwoCVTransform() {
181+
type_ = RuleType::TV_EQUALITY_WITH_TWO_CV;
182182

183183
// (A.B = x) AND (A.B = y)
184184
match_pattern = std::make_shared<Pattern<ExpressionType>>(ExpressionType::CONJUNCTION_AND);
@@ -199,23 +199,39 @@ TransitiveSingleDepthTransform::TransitiveSingleDepthTransform() {
199199
match_pattern->AddChild(r_eq);
200200
}
201201

202+
<<<<<<< Updated upstream
202203
int TransitiveSingleDepthTransform::Promise(GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
204+
=======
205+
int TVEqualityWithTwoCVTransform::Promise(GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
206+
>>>>>>> Stashed changes
203207
(void)group_expr;
204208
(void)context;
205209
return static_cast<int>(RulePriority::HIGH);
206210
}
207211

212+
<<<<<<< Updated upstream
208213
bool TransitiveSingleDepthTransform::Check(std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
214+
=======
215+
bool TVEqualityWithTwoCVTransform::Check(std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
216+
>>>>>>> Stashed changes
209217
(void)plan;
210218
(void)context;
211219
return true;
212220
}
213221

222+
<<<<<<< Updated upstream
214223
void TransitiveSingleDepthTransform::Transform(std::shared_ptr<AbsExpr_Expression> input,
215224
std::vector<std::shared_ptr<AbsExpr_Expression>> &transformed,
216225
OptimizeContextTemplate *context) const {
217226
(void)context;
218227
//TODO(wz2): TransitiveClosureConstant should work beyond straight equality
228+
=======
229+
void TVEqualityWithTwoCVTransform::Transform(std::shared_ptr<AbsExpr_Expression> input,
230+
std::vector<std::shared_ptr<AbsExpr_Expression>> &transformed,
231+
OptimizeContextTemplate *context) const {
232+
(void)context;
233+
//TODO(wz2): TVEqualityWithTwoCVTransform should work beyond straight equality
234+
>>>>>>> Stashed changes
219235

220236
// Asserting guarantees provided by the GroupExprBindingIterator
221237
// Structure: (A.B = x) AND (A.B = y)
@@ -344,7 +360,11 @@ void TransitiveClosureConstantTransform::Transform(std::shared_ptr<AbsExpr_Expre
344360
PELOTON_ASSERT(l_tv->Children().size() == 0);
345361
PELOTON_ASSERT(l_cv->Children().size() == 0);
346362
PELOTON_ASSERT(l_tv->Op().GetType() == ExpressionType::VALUE_TUPLE);
363+
<<<<<<< Updated upstream
347364
PELOTON_ASSERT(l_tv->Op().GetType() == ExpressionType::VALUE_CONSTANT);
365+
=======
366+
PELOTON_ASSERT(l_cv->Op().GetType() == ExpressionType::VALUE_CONSTANT);
367+
>>>>>>> Stashed changes
348368

349369
auto r_tv_l = r_eq->Children()[0];
350370
auto r_tv_r = r_eq->Children()[1];
@@ -386,7 +406,11 @@ void TransitiveClosureConstantTransform::Transform(std::shared_ptr<AbsExpr_Expre
386406
new_right_eq->PushChild(r_tv_r);
387407
} else {
388408
// At this stage, we have knowledge that A.B = E.F
409+
<<<<<<< Updated upstream
389410
new_right_eq->PushChild(r_tv_r);
411+
=======
412+
new_right_eq->PushChild(r_tv_l);
413+
>>>>>>> Stashed changes
390414
new_right_eq->PushChild(right_val_copy);
391415
}
392416

src/traffic_cop/traffic_cop.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,15 @@ ResultType TrafficCop::ExecuteStatement(
581581
statement, std::move(param_stats));
582582
}
583583

584-
LOG_TRACE("Execute Statement of name: %s",
584+
LOG_DEBUG("Execute Statement of name: %s",
585585
statement->GetStatementName().c_str());
586-
LOG_TRACE("Execute Statement of query: %s",
586+
LOG_DEBUG("Execute Statement of query: %s",
587587
statement->GetQueryString().c_str());
588-
LOG_TRACE("Execute Statement Plan:\n%s",
588+
LOG_DEBUG("Execute Statement Plan:\n%s",
589589
planner::PlanUtil::GetInfo(statement->GetPlanTree().get()).c_str());
590-
LOG_TRACE("Execute Statement Query Type: %s",
590+
LOG_DEBUG("Execute Statement Query Type: %s",
591591
statement->GetQueryTypeString().c_str());
592-
LOG_TRACE("----QueryType: %d--------",
592+
LOG_DEBUG("----QueryType: %d--------",
593593
static_cast<int>(statement->GetQueryType()));
594594

595595
try {

0 commit comments

Comments
 (0)