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

Commit 6578dca

Browse files
author
Erik Sargent
committed
Pulled equiv-experimental into branch
2 parents 60162f5 + f4bf21c commit 6578dca

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

src/include/optimizer/rule.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,8 @@ struct RuleWithPromise {
114114
enum class RewriteRuleSetName : uint32_t {
115115
PREDICATE_PUSH_DOWN = 0,
116116
UNNEST_SUBQUERY,
117-
COMPARATOR_ELIMINATION,
118117
EQUIVALENT_TRANSFORM,
119-
TRANSITIVE_TRANSFORM,
120-
BOOLEAN_SHORT_CIRCUIT,
121-
NULL_LOOKUP
118+
GENERIC_RULES
122119
};
123120

124121
/**

src/optimizer/rewriter.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ void Rewriter::RewriteLoop(int root_group_id) {
6565
auto task_stack = std::unique_ptr<OptimizerTaskStackTemplate>(new OptimizerTaskStackTemplate());
6666
metadata_.SetTaskPool(task_stack.get());
6767

68-
// Perform rewrite first
69-
task_stack->Push(new TopDownRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::BOOLEAN_SHORT_CIRCUIT));
70-
task_stack->Push(new BottomUpRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::TRANSITIVE_TRANSFORM, false));
71-
task_stack->Push(new BottomUpRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::COMPARATOR_ELIMINATION, false));
68+
// Rewrite using all rules (which will be applied based on priority)
69+
task_stack->Push(new BottomUpRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::GENERIC_RULES, false));
7270

73-
task_stack->Push(new BottomUpRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::NULL_LOOKUP, false));
71+
// Generate equivalences first
7472
auto equiv_task = new TopDownRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::EQUIVALENT_TRANSFORM);
7573
equiv_task->SetReplaceOnTransform(false); // generate equivalent
7674
task_stack->Push(equiv_task);

src/optimizer/rule.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ RuleSet<AbsExpr_Container,ExpressionType,AbsExpr_Expression>::RuleSet() {
6767

6868
for (auto &pair : comp_elim_pairs) {
6969
AddRewriteRule(
70-
RewriteRuleSetName::COMPARATOR_ELIMINATION,
70+
RewriteRuleSetName::GENERIC_RULES,
7171
new ComparatorElimination(pair.first, pair.second)
7272
);
7373
}
@@ -86,14 +86,14 @@ RuleSet<AbsExpr_Container,ExpressionType,AbsExpr_Expression>::RuleSet() {
8686
}
8787

8888
// Additional rules
89-
AddRewriteRule(RewriteRuleSetName::TRANSITIVE_TRANSFORM, new TVEqualityWithTwoCVTransform());
90-
AddRewriteRule(RewriteRuleSetName::TRANSITIVE_TRANSFORM, new TransitiveClosureConstantTransform());
89+
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new TVEqualityWithTwoCVTransform());
90+
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new TransitiveClosureConstantTransform());
9191

92-
AddRewriteRule(RewriteRuleSetName::BOOLEAN_SHORT_CIRCUIT, new AndShortCircuit());
93-
AddRewriteRule(RewriteRuleSetName::BOOLEAN_SHORT_CIRCUIT, new OrShortCircuit());
92+
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new AndShortCircuit());
93+
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new OrShortCircuit());
9494

95-
AddRewriteRule(RewriteRuleSetName::NULL_LOOKUP, new NullLookupOnNotNullColumn());
96-
AddRewriteRule(RewriteRuleSetName::NULL_LOOKUP, new NotNullLookupOnNotNullColumn());
95+
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new NullLookupOnNotNullColumn());
96+
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new NotNullLookupOnNotNullColumn());
9797
}
9898

9999
template <>

src/optimizer/rule_rewrite.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int ComparatorElimination::Promise(GroupExprTemplate *group_expr,
3737
OptimizeContextTemplate *context) const {
3838
(void)group_expr;
3939
(void)context;
40-
return static_cast<int>(RulePriority::HIGH);
40+
return static_cast<int>(RulePriority::MEDIUM);
4141
}
4242

4343
bool ComparatorElimination::Check(std::shared_ptr<AbsExpr_Expression> plan,
@@ -202,7 +202,7 @@ TVEqualityWithTwoCVTransform::TVEqualityWithTwoCVTransform() {
202202
int TVEqualityWithTwoCVTransform::Promise(GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
203203
(void)group_expr;
204204
(void)context;
205-
return static_cast<int>(RulePriority::HIGH);
205+
return static_cast<int>(RulePriority::LOW);
206206
}
207207

208208
bool TVEqualityWithTwoCVTransform::Check(std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
@@ -312,7 +312,7 @@ TransitiveClosureConstantTransform::TransitiveClosureConstantTransform() {
312312
int TransitiveClosureConstantTransform::Promise(GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
313313
(void)group_expr;
314314
(void)context;
315-
return static_cast<int>(RulePriority::HIGH);
315+
return static_cast<int>(RulePriority::LOW);
316316
}
317317

318318
bool TransitiveClosureConstantTransform::Check(std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
@@ -387,6 +387,7 @@ void TransitiveClosureConstantTransform::Transform(std::shared_ptr<AbsExpr_Expre
387387
} else {
388388
// At this stage, we have knowledge that A.B = E.F
389389
new_right_eq->PushChild(r_tv_l);
390+
new_right_eq->PushChild(right_val_copy);
390391
}
391392

392393
// Create new root expression

0 commit comments

Comments
 (0)