@@ -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 ) ]
@@ -25,7 +25,7 @@ impl BestCubePlan {
2525 }
2626 }
2727
28- pub fn initial_cost ( & self , enode : & LogicalPlanLanguage , top_down : bool ) -> CubePlanCost {
28+ pub fn initial_cost ( & self , enode : & LogicalPlanLanguage ) -> CubePlanCost {
2929 let table_scans = match enode {
3030 LogicalPlanLanguage :: TableScan ( _) => 1 ,
3131 _ => 0 ,
@@ -52,8 +52,7 @@ impl BestCubePlan {
5252 } ;
5353
5454 let non_pushed_down_limit_sort = match enode {
55- LogicalPlanLanguage :: Limit ( _) if !top_down => 1 ,
56- LogicalPlanLanguage :: Sort ( _) if top_down => 1 ,
55+ LogicalPlanLanguage :: Sort ( _) => 1 ,
5756 _ => 0 ,
5857 } ;
5958
@@ -248,7 +247,6 @@ impl BestCubePlan {
248247
249248#[ derive( Clone , Copy ) ]
250249pub struct CubePlanCostOptions {
251- top_down : bool ,
252250 penalize_post_processing : bool ,
253251}
254252
@@ -312,73 +310,13 @@ pub enum CubePlanState {
312310 Wrapper ,
313311}
314312
315- impl CubePlanState {
316- pub fn add_child ( & self , other : & Self ) -> Self {
317- match ( self , other) {
318- ( CubePlanState :: Wrapper , _) => CubePlanState :: Wrapper ,
319- ( _, CubePlanState :: Wrapped ) => CubePlanState :: Wrapped ,
320- ( CubePlanState :: Wrapped , _) => CubePlanState :: Wrapped ,
321- ( CubePlanState :: Unwrapped ( a) , _) => CubePlanState :: Unwrapped ( * a) ,
322- }
323- }
324- }
325-
326313#[ derive( Debug , Clone , Eq , Hash , PartialEq ) ]
327314pub enum SortState {
328315 None ,
329316 Current ,
330317 DirectChild ,
331318}
332319
333- impl SortState {
334- pub fn add_child ( & self , other : & Self ) -> Self {
335- match ( self , other) {
336- ( Self :: Current , _) => Self :: Current ,
337- ( _, Self :: Current ) | ( Self :: DirectChild , _) => Self :: DirectChild ,
338- _ => Self :: None ,
339- }
340- }
341- }
342-
343- #[ derive( Debug , Clone , Eq , PartialEq ) ]
344- pub struct CubePlanCostAndState {
345- pub cost : CubePlanCost ,
346- pub state : CubePlanState ,
347- pub sort_state : SortState ,
348- }
349-
350- impl PartialOrd for CubePlanCostAndState {
351- fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
352- Some ( self . cost . cmp ( & other. cost ) )
353- }
354- }
355-
356- impl Ord for CubePlanCostAndState {
357- fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
358- self . cost . cmp ( & other. cost )
359- }
360- }
361-
362- impl CubePlanCostAndState {
363- pub fn add_child ( & self , other : & Self ) -> Self {
364- Self {
365- cost : self . cost . add_child ( & other. cost ) ,
366- state : self . state . add_child ( & other. state ) ,
367- sort_state : self . sort_state . add_child ( & other. sort_state ) ,
368- }
369- }
370-
371- pub fn finalize ( & self , enode : & LogicalPlanLanguage , options : CubePlanCostOptions ) -> Self {
372- Self {
373- cost : self
374- . cost
375- . finalize ( & self . state , & self . sort_state , enode, options) ,
376- state : self . state . clone ( ) ,
377- sort_state : self . sort_state . clone ( ) ,
378- }
379- }
380- }
381-
382320impl CubePlanCost {
383321 pub fn add_child ( & self , other : & Self ) -> Self {
384322 Self {
@@ -469,7 +407,7 @@ impl CubePlanCost {
469407 } ,
470408 non_pushed_down_limit_sort : match sort_state {
471409 SortState :: DirectChild => self . non_pushed_down_limit_sort ,
472- SortState :: Current if options . top_down => self . non_pushed_down_limit_sort ,
410+ SortState :: Current => self . non_pushed_down_limit_sort ,
473411 _ => 0 ,
474412 } ,
475413 // Don't track state here: we want representation that have fewer wrappers with zero members _in total_
@@ -520,60 +458,6 @@ impl CubePlanCost {
520458 }
521459}
522460
523- impl CostFunction < LogicalPlanLanguage > for BestCubePlan {
524- type Cost = CubePlanCostAndState ;
525- fn cost < C > ( & mut self , enode : & LogicalPlanLanguage , mut costs : C ) -> Self :: Cost
526- where
527- C : FnMut ( Id ) -> Self :: Cost ,
528- {
529- let ast_size_outside_wrapper = match enode {
530- LogicalPlanLanguage :: Aggregate ( _) => 1 ,
531- LogicalPlanLanguage :: Projection ( _) => 1 ,
532- LogicalPlanLanguage :: Limit ( _) => 1 ,
533- LogicalPlanLanguage :: Sort ( _) => 1 ,
534- LogicalPlanLanguage :: Filter ( _) => 1 ,
535- LogicalPlanLanguage :: Join ( _) => 1 ,
536- LogicalPlanLanguage :: CrossJoin ( _) => 1 ,
537- LogicalPlanLanguage :: Union ( _) => 1 ,
538- LogicalPlanLanguage :: Window ( _) => 1 ,
539- LogicalPlanLanguage :: Subquery ( _) => 1 ,
540- LogicalPlanLanguage :: Distinct ( _) => 1 ,
541- _ => 0 ,
542- } ;
543-
544- let cost = self . initial_cost ( enode, false ) ;
545- let initial_cost = CubePlanCostAndState {
546- cost,
547- state : match enode {
548- LogicalPlanLanguage :: CubeScanWrapped ( CubeScanWrapped ( true ) ) => {
549- CubePlanState :: Wrapped
550- }
551- LogicalPlanLanguage :: CubeScanWrapper ( _) => CubePlanState :: Wrapper ,
552- _ => CubePlanState :: Unwrapped ( ast_size_outside_wrapper) ,
553- } ,
554- sort_state : match enode {
555- LogicalPlanLanguage :: Sort ( _) => SortState :: Current ,
556- _ => SortState :: None ,
557- } ,
558- } ;
559- let res = enode
560- . children ( )
561- . iter ( )
562- . fold ( initial_cost. clone ( ) , |cost, id| {
563- let child = costs ( * id) ;
564- cost. add_child ( & child)
565- } )
566- . finalize (
567- enode,
568- CubePlanCostOptions {
569- top_down : false ,
570- penalize_post_processing : self . penalize_post_processing ,
571- } ,
572- ) ;
573- res
574- }
575- }
576-
577461pub trait TopDownCost : Clone + Debug + PartialOrd {
578462 fn add ( & self , other : & Self ) -> Self ;
579463}
@@ -902,7 +786,7 @@ impl TopDownState<LogicalPlanLanguage> for CubePlanTopDownState {
902786
903787impl TopDownCostFunction < LogicalPlanLanguage , CubePlanTopDownState , CubePlanCost > for BestCubePlan {
904788 fn cost ( & self , node : & LogicalPlanLanguage ) -> CubePlanCost {
905- self . initial_cost ( node, true )
789+ self . initial_cost ( node)
906790 }
907791
908792 fn finalize (
@@ -917,7 +801,6 @@ impl TopDownCostFunction<LogicalPlanLanguage, CubePlanTopDownState, CubePlanCost
917801 & state. limit ,
918802 node,
919803 CubePlanCostOptions {
920- top_down : true ,
921804 penalize_post_processing : self . penalize_post_processing ,
922805 } ,
923806 )
0 commit comments