Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing Optimizer #875

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions src/planner/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,47 @@ impl Optimizer {
}
}

/// Optimize the given expression.
pub fn optimize(&self, mut expr: RecExpr) -> RecExpr {
let mut cost = f32::MAX;

// define extra rules for some configurations
let mut extra_rules = vec![];
if self.analysis.config.enable_range_filter_scan {
extra_rules.append(&mut rules::range::filter_scan_rule());
}

// 1. pushdown apply
self.optimize_stage(&mut expr, &mut cost, STAGE1_RULES.iter(), 2, 6);
// 2. pushdown predicate and projection
let rules = STAGE2_RULES.iter().chain(&extra_rules);
self.optimize_stage(&mut expr, &mut cost, rules, 4, 6);
// 3. join reorder and hashjoin
self.optimize_stage(&mut expr, &mut cost, STAGE3_RULES.iter(), 3, 8);
expr
/// Optimize the given expression.
pub fn optimize(&self, mut expr: RecExpr) -> RecExpr {
let mut cost = f32::MAX;

// Define extra rules for some configurations
let mut extra_rules = vec![];
if self.analysis.config.enable_range_filter_scan {
extra_rules.append(&mut rules::range::filter_scan_rule());
}

// Print initial expression and cost
println!("[Initial] Expression: {:?}", expr);
println!("[Initial] Cost: {}", cost);
println!("");

// 1. pushdown apply
self.optimize_stage(&mut expr, &mut cost, STAGE1_RULES.iter(), 2, 6);
println!("[After Stage 1] Expression: {:?}", expr);
println!("[After Stage 1] Cost: {}", cost);
println!("");

// 2. pushdown predicate and projection
let rules = STAGE2_RULES.iter().chain(&extra_rules);
self.optimize_stage(&mut expr, &mut cost, rules, 4, 6);
println!("[After Stage 2] Expression: {:?}", expr);
println!("[After Stage 2] Cost: {}", cost);
println!("");

// 3. join reorder and hashjoin
self.optimize_stage(&mut expr, &mut cost, STAGE3_RULES.iter(), 3, 8);
println!("[After Stage 3] Expression: {:?}", expr);
println!("[After Stage 3] Cost: {}", cost);
println!("");

// Print final expression and cost
println!("[Final] Expression: {:?}", expr);
println!("[Final] Cost: {}", cost);
println!("");

expr
}
/// Optimize the expression with the given rules in multiple iterations.
/// In each iteration, the best expression is selected as the input of the next iteration.
fn optimize_stage<'a>(
Expand Down
Loading