@@ -32,26 +32,47 @@ impl Optimizer {
3232 }
3333 }
3434
35- /// Optimize the given expression.
36- pub fn optimize ( & self , mut expr : RecExpr ) -> RecExpr {
37- let mut cost = f32:: MAX ;
38-
39- // define extra rules for some configurations
40- let mut extra_rules = vec ! [ ] ;
41- if self . analysis . config . enable_range_filter_scan {
42- extra_rules. append ( & mut rules:: range:: filter_scan_rule ( ) ) ;
43- }
44-
45- // 1. pushdown apply
46- self . optimize_stage ( & mut expr, & mut cost, STAGE1_RULES . iter ( ) , 2 , 6 ) ;
47- // 2. pushdown predicate and projection
48- let rules = STAGE2_RULES . iter ( ) . chain ( & extra_rules) ;
49- self . optimize_stage ( & mut expr, & mut cost, rules, 4 , 6 ) ;
50- // 3. join reorder and hashjoin
51- self . optimize_stage ( & mut expr, & mut cost, STAGE3_RULES . iter ( ) , 3 , 8 ) ;
52- expr
35+ /// Optimize the given expression.
36+ pub fn optimize ( & self , mut expr : RecExpr ) -> RecExpr {
37+ let mut cost = f32:: MAX ;
38+
39+ // Define extra rules for some configurations
40+ let mut extra_rules = vec ! [ ] ;
41+ if self . analysis . config . enable_range_filter_scan {
42+ extra_rules. append ( & mut rules:: range:: filter_scan_rule ( ) ) ;
5343 }
5444
45+ // Print initial expression and cost
46+ println ! ( "[Initial] Expression: {:?}" , expr) ;
47+ println ! ( "[Initial] Cost: {}" , cost) ;
48+ println ! ( "" ) ;
49+
50+ // 1. pushdown apply
51+ self . optimize_stage ( & mut expr, & mut cost, STAGE1_RULES . iter ( ) , 2 , 6 ) ;
52+ println ! ( "[After Stage 1] Expression: {:?}" , expr) ;
53+ println ! ( "[After Stage 1] Cost: {}" , cost) ;
54+ println ! ( "" ) ;
55+
56+ // 2. pushdown predicate and projection
57+ let rules = STAGE2_RULES . iter ( ) . chain ( & extra_rules) ;
58+ self . optimize_stage ( & mut expr, & mut cost, rules, 4 , 6 ) ;
59+ println ! ( "[After Stage 2] Expression: {:?}" , expr) ;
60+ println ! ( "[After Stage 2] Cost: {}" , cost) ;
61+ println ! ( "" ) ;
62+
63+ // 3. join reorder and hashjoin
64+ self . optimize_stage ( & mut expr, & mut cost, STAGE3_RULES . iter ( ) , 3 , 8 ) ;
65+ println ! ( "[After Stage 3] Expression: {:?}" , expr) ;
66+ println ! ( "[After Stage 3] Cost: {}" , cost) ;
67+ println ! ( "" ) ;
68+
69+ // Print final expression and cost
70+ println ! ( "[Final] Expression: {:?}" , expr) ;
71+ println ! ( "[Final] Cost: {}" , cost) ;
72+ println ! ( "" ) ;
73+
74+ expr
75+ }
5576 /// Optimize the expression with the given rules in multiple iterations.
5677 /// In each iteration, the best expression is selected as the input of the next iteration.
5778 fn optimize_stage < ' a > (
0 commit comments