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

Commit

Permalink
Consolidated most rules into a single ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
17zhangw committed May 4, 2019
1 parent df63fd8 commit f4bf21c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/include/optimizer/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ struct RuleWithPromise {
enum class RewriteRuleSetName : uint32_t {
PREDICATE_PUSH_DOWN = 0,
UNNEST_SUBQUERY,
COMPARATOR_ELIMINATION,
EQUIVALENT_TRANSFORM,
TRANSITIVE_TRANSFORM
GENERIC_RULES
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/optimizer/rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ void Rewriter::RewriteLoop(int root_group_id) {
auto task_stack = std::unique_ptr<OptimizerTaskStackTemplate>(new OptimizerTaskStackTemplate());
metadata_.SetTaskPool(task_stack.get());

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

// Generate equivalences first
auto equiv_task = new TopDownRewriteTemplate(root_group_id, root_context, RewriteRuleSetName::EQUIVALENT_TRANSFORM);
equiv_task->SetReplaceOnTransform(false); // generate equivalent
task_stack->Push(equiv_task);
Expand Down
6 changes: 3 additions & 3 deletions src/optimizer/rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RuleSet<AbsExpr_Container,ExpressionType,AbsExpr_Expression>::RuleSet() {

for (auto &pair : comp_elim_pairs) {
AddRewriteRule(
RewriteRuleSetName::COMPARATOR_ELIMINATION,
RewriteRuleSetName::GENERIC_RULES,
new ComparatorElimination(pair.first, pair.second)
);
}
Expand All @@ -86,8 +86,8 @@ RuleSet<AbsExpr_Container,ExpressionType,AbsExpr_Expression>::RuleSet() {
}

// Additional rules
AddRewriteRule(RewriteRuleSetName::TRANSITIVE_TRANSFORM, new TVEqualityWithTwoCVTransform());
AddRewriteRule(RewriteRuleSetName::TRANSITIVE_TRANSFORM, new TransitiveClosureConstantTransform());
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new TVEqualityWithTwoCVTransform());
AddRewriteRule(RewriteRuleSetName::GENERIC_RULES, new TransitiveClosureConstantTransform());
}

template <>
Expand Down
6 changes: 3 additions & 3 deletions src/optimizer/rule_rewrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int ComparatorElimination::Promise(GroupExprTemplate *group_expr,
OptimizeContextTemplate *context) const {
(void)group_expr;
(void)context;
return static_cast<int>(RulePriority::HIGH);
return static_cast<int>(RulePriority::MEDIUM);
}

bool ComparatorElimination::Check(std::shared_ptr<AbsExpr_Expression> plan,
Expand Down Expand Up @@ -202,7 +202,7 @@ TVEqualityWithTwoCVTransform::TVEqualityWithTwoCVTransform() {
int TVEqualityWithTwoCVTransform::Promise(GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
(void)group_expr;
(void)context;
return static_cast<int>(RulePriority::HIGH);
return static_cast<int>(RulePriority::LOW);
}

bool TVEqualityWithTwoCVTransform::Check(std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
Expand Down Expand Up @@ -312,7 +312,7 @@ TransitiveClosureConstantTransform::TransitiveClosureConstantTransform() {
int TransitiveClosureConstantTransform::Promise(GroupExprTemplate *group_expr, OptimizeContextTemplate *context) const {
(void)group_expr;
(void)context;
return static_cast<int>(RulePriority::HIGH);
return static_cast<int>(RulePriority::LOW);
}

bool TransitiveClosureConstantTransform::Check(std::shared_ptr<AbsExpr_Expression> plan, OptimizeContextTemplate *context) const {
Expand Down

0 comments on commit f4bf21c

Please sign in to comment.