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

Commit f4bf21c

Browse files
committed
Consolidated most rules into a single ruleset
1 parent df63fd8 commit f4bf21c

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

src/include/optimizer/rule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +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
118+
GENERIC_RULES
120119
};
121120

122121
/**

src/optimizer/rewriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +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 BottomUpRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::TRANSITIVE_TRANSFORM, false));
70-
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));
7170

71+
// Generate equivalences first
7272
auto equiv_task = new TopDownRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::EQUIVALENT_TRANSFORM);
7373
equiv_task->SetReplaceOnTransform(false); // generate equivalent
7474
task_stack->Push(equiv_task);

src/optimizer/rule.cpp

Lines changed: 3 additions & 3 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,8 +86,8 @@ 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
}
9292

9393
template <>

src/optimizer/rule_rewrite.cpp

Lines changed: 3 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 {

0 commit comments

Comments
 (0)