@@ -8,7 +8,7 @@ use crate::{
88 } ,
99 transport:: { MetaContext , V1CubeMetaDimensionExt } ,
1010} ;
11- use egg:: { Analysis , CostFunction , EGraph , Id , Language , RecExpr } ;
11+ use egg:: { Analysis , EGraph , Id , Language , RecExpr } ;
1212use indexmap:: IndexSet ;
1313
1414#[ derive( Debug ) ]
@@ -21,7 +21,7 @@ impl BestCubePlan {
2121 Self { meta_context }
2222 }
2323
24- pub fn initial_cost ( & self , enode : & LogicalPlanLanguage , top_down : bool ) -> CubePlanCost {
24+ pub fn initial_cost ( & self , enode : & LogicalPlanLanguage ) -> CubePlanCost {
2525 let table_scans = match enode {
2626 LogicalPlanLanguage :: TableScan ( _) => 1 ,
2727 _ => 0 ,
@@ -48,8 +48,7 @@ impl BestCubePlan {
4848 } ;
4949
5050 let non_pushed_down_limit_sort = match enode {
51- LogicalPlanLanguage :: Limit ( _) if !top_down => 1 ,
52- LogicalPlanLanguage :: Sort ( _) if top_down => 1 ,
51+ LogicalPlanLanguage :: Sort ( _) => 1 ,
5352 _ => 0 ,
5453 } ;
5554
@@ -315,45 +314,6 @@ impl SortState {
315314 }
316315}
317316
318- #[ derive( Debug , Clone , Eq , PartialEq ) ]
319- pub struct CubePlanCostAndState {
320- pub cost : CubePlanCost ,
321- pub state : CubePlanState ,
322- pub sort_state : SortState ,
323- }
324-
325- impl PartialOrd for CubePlanCostAndState {
326- fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
327- Some ( self . cost . cmp ( & other. cost ) )
328- }
329- }
330-
331- impl Ord for CubePlanCostAndState {
332- fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
333- self . cost . cmp ( & other. cost )
334- }
335- }
336-
337- impl CubePlanCostAndState {
338- pub fn add_child ( & self , other : & Self ) -> Self {
339- Self {
340- cost : self . cost . add_child ( & other. cost ) ,
341- state : self . state . add_child ( & other. state ) ,
342- sort_state : self . sort_state . add_child ( & other. sort_state ) ,
343- }
344- }
345-
346- pub fn finalize ( & self , enode : & LogicalPlanLanguage ) -> Self {
347- Self {
348- cost : self
349- . cost
350- . finalize ( & self . state , & self . sort_state , enode, false ) ,
351- state : self . state . clone ( ) ,
352- sort_state : self . sort_state . clone ( ) ,
353- }
354- }
355- }
356-
357317impl CubePlanCost {
358318 pub fn add_child ( & self , other : & Self ) -> Self {
359319 Self {
@@ -407,7 +367,6 @@ impl CubePlanCost {
407367 state : & CubePlanState ,
408368 sort_state : & SortState ,
409369 enode : & LogicalPlanLanguage ,
410- top_down : bool ,
411370 ) -> Self {
412371 Self {
413372 replacers : self . replacers ,
@@ -428,7 +387,7 @@ impl CubePlanCost {
428387 } ,
429388 non_pushed_down_limit_sort : match sort_state {
430389 SortState :: DirectChild => self . non_pushed_down_limit_sort ,
431- SortState :: Current if top_down => self . non_pushed_down_limit_sort ,
390+ SortState :: Current => self . non_pushed_down_limit_sort ,
432391 _ => 0 ,
433392 } ,
434393 // Don't track state here: we want representation that have fewer wrappers with zero members _in total_
@@ -482,54 +441,6 @@ impl CubePlanCost {
482441 }
483442}
484443
485- impl CostFunction < LogicalPlanLanguage > for BestCubePlan {
486- type Cost = CubePlanCostAndState ;
487- fn cost < C > ( & mut self , enode : & LogicalPlanLanguage , mut costs : C ) -> Self :: Cost
488- where
489- C : FnMut ( Id ) -> Self :: Cost ,
490- {
491- let ast_size_outside_wrapper = match enode {
492- LogicalPlanLanguage :: Aggregate ( _) => 1 ,
493- LogicalPlanLanguage :: Projection ( _) => 1 ,
494- LogicalPlanLanguage :: Limit ( _) => 1 ,
495- LogicalPlanLanguage :: Sort ( _) => 1 ,
496- LogicalPlanLanguage :: Filter ( _) => 1 ,
497- LogicalPlanLanguage :: Join ( _) => 1 ,
498- LogicalPlanLanguage :: CrossJoin ( _) => 1 ,
499- LogicalPlanLanguage :: Union ( _) => 1 ,
500- LogicalPlanLanguage :: Window ( _) => 1 ,
501- LogicalPlanLanguage :: Subquery ( _) => 1 ,
502- LogicalPlanLanguage :: Distinct ( _) => 1 ,
503- _ => 0 ,
504- } ;
505-
506- let cost = self . initial_cost ( enode, false ) ;
507- let initial_cost = CubePlanCostAndState {
508- cost,
509- state : match enode {
510- LogicalPlanLanguage :: CubeScanWrapped ( CubeScanWrapped ( true ) ) => {
511- CubePlanState :: Wrapped
512- }
513- LogicalPlanLanguage :: CubeScanWrapper ( _) => CubePlanState :: Wrapper ,
514- _ => CubePlanState :: Unwrapped ( ast_size_outside_wrapper) ,
515- } ,
516- sort_state : match enode {
517- LogicalPlanLanguage :: Sort ( _) => SortState :: Current ,
518- _ => SortState :: None ,
519- } ,
520- } ;
521- let res = enode
522- . children ( )
523- . iter ( )
524- . fold ( initial_cost. clone ( ) , |cost, id| {
525- let child = costs ( * id) ;
526- cost. add_child ( & child)
527- } )
528- . finalize ( enode) ;
529- res
530- }
531- }
532-
533444pub trait TopDownCost : Clone + Debug + PartialOrd {
534445 fn add ( & self , other : & Self ) -> Self ;
535446}
@@ -858,7 +769,7 @@ impl TopDownState<LogicalPlanLanguage> for CubePlanTopDownState {
858769
859770impl TopDownCostFunction < LogicalPlanLanguage , CubePlanTopDownState , CubePlanCost > for BestCubePlan {
860771 fn cost ( & self , node : & LogicalPlanLanguage ) -> CubePlanCost {
861- self . initial_cost ( node, true )
772+ self . initial_cost ( node)
862773 }
863774
864775 fn finalize (
@@ -867,6 +778,6 @@ impl TopDownCostFunction<LogicalPlanLanguage, CubePlanTopDownState, CubePlanCost
867778 node : & LogicalPlanLanguage ,
868779 state : & CubePlanTopDownState ,
869780 ) -> CubePlanCost {
870- CubePlanCost :: finalize ( & cost, & state. wrapped , & state. limit , node, true )
781+ CubePlanCost :: finalize ( & cost, & state. wrapped , & state. limit , node)
871782 }
872783}
0 commit comments