@@ -27,7 +27,6 @@ use super::algorithm::JoinEdgeRef;
2727use super :: algorithm:: JoinNode ;
2828use super :: algorithm:: JoinOrderModel ;
2929use crate :: IndexType ;
30- use crate :: ScalarExpr ;
3130use crate :: optimizer:: Optimizer ;
3231use crate :: optimizer:: OptimizerContext ;
3332use crate :: optimizer:: ir:: RelExpr ;
@@ -59,7 +58,7 @@ pub struct DPhpyOptimizer {
5958
6059struct DPhypJoinOrderModel < ' a > {
6160 join_relations : & ' a [ JoinRelation ] ,
62- join_conditions : & ' a [ ( ScalarExpr , ScalarExpr ) ] ,
61+ join_conditions : & ' a [ JoinEquiCondition ] ,
6362}
6463
6564impl DPhypJoinOrderModel < ' _ > {
@@ -71,17 +70,14 @@ impl DPhypJoinOrderModel<'_> {
7170 ) -> SExpr {
7271 let left_expr = left. state ( ) . clone ( ) ;
7372 let right_expr = right. state ( ) . clone ( ) ;
74- let mut left_conditions = Vec :: with_capacity ( edge_refs. len ( ) ) ;
75- let mut right_conditions = Vec :: with_capacity ( edge_refs. len ( ) ) ;
73+ let mut conditions = Vec :: with_capacity ( edge_refs. len ( ) ) ;
7674
7775 for edge_ref in edge_refs {
78- let ( mut left_condition, mut right_condition) =
79- self . join_conditions [ edge_ref. id ] . clone ( ) ;
76+ let mut condition = self . join_conditions [ edge_ref. id ] . clone ( ) ;
8077 if edge_ref. reversed {
81- std:: mem:: swap ( & mut left_condition , & mut right_condition ) ;
78+ std:: mem:: swap ( & mut condition . left , & mut condition . right ) ;
8279 }
83- left_conditions. push ( left_condition) ;
84- right_conditions. push ( right_condition) ;
80+ conditions. push ( condition) ;
8581 }
8682
8783 let join_type = if edge_refs. is_empty ( ) {
@@ -90,11 +86,7 @@ impl DPhypJoinOrderModel<'_> {
9086 JoinType :: Inner
9187 } ;
9288 let rel_op = RelOperator :: Join ( Join {
93- equi_conditions : JoinEquiCondition :: new_conditions (
94- left_conditions,
95- right_conditions,
96- vec ! [ ] ,
97- ) ,
89+ equi_conditions : conditions,
9890 non_equi_conditions : vec ! [ ] ,
9991 join_type,
10092 marker_index : None ,
@@ -269,7 +261,7 @@ impl DPhpyOptimizer {
269261 async fn process_join_node (
270262 & mut self ,
271263 s_expr : & SExpr ,
272- join_conditions : & mut Vec < ( ScalarExpr , ScalarExpr ) > ,
264+ join_conditions : & mut Vec < JoinEquiCondition > ,
273265 ) -> Result < ( Arc < SExpr > , bool ) > {
274266 let op = match s_expr. plan ( ) {
275267 RelOperator :: Join ( op) => op,
@@ -304,7 +296,7 @@ impl DPhpyOptimizer {
304296 break ;
305297 }
306298
307- join_conditions. push ( ( condition. left . clone ( ) , condition . right . clone ( ) ) ) ;
299+ join_conditions. push ( condition. clone ( ) ) ;
308300 }
309301
310302 // Add non-equi conditions to filters
@@ -571,7 +563,7 @@ impl DPhpyOptimizer {
571563 async fn process_unary_node (
572564 & mut self ,
573565 s_expr : & SExpr ,
574- join_conditions : & mut Vec < ( ScalarExpr , ScalarExpr ) > ,
566+ join_conditions : & mut Vec < JoinEquiCondition > ,
575567 join_child : bool ,
576568 join_relation : Option < & SExpr > ,
577569 ) -> Result < ( Arc < SExpr > , bool ) > {
@@ -611,7 +603,7 @@ impl DPhpyOptimizer {
611603 async fn get_base_relations (
612604 & mut self ,
613605 s_expr : & SExpr ,
614- join_conditions : & mut Vec < ( ScalarExpr , ScalarExpr ) > ,
606+ join_conditions : & mut Vec < JoinEquiCondition > ,
615607 join_child : bool ,
616608 join_relation : Option < & SExpr > ,
617609 is_subquery : bool ,
@@ -673,7 +665,6 @@ impl DPhpyOptimizer {
673665 }
674666
675667 // Firstly, we need to extract all join conditions and base tables
676- // `join_condition` is pair, left is left_condition, right is right_condition
677668 let mut join_conditions = vec ! [ ] ;
678669 let ( s_expr, optimized) = self
679670 . get_base_relations ( s_expr, & mut join_conditions, false , None , false )
@@ -715,18 +706,18 @@ impl DPhpyOptimizer {
715706 fn build_join_order_edges (
716707 & self ,
717708 hyper_dp : & mut HyperDp < ' _ , DPhypJoinOrderModel < ' _ > > ,
718- join_conditions : & [ ( ScalarExpr , ScalarExpr ) ] ,
709+ join_conditions : & [ JoinEquiCondition ] ,
719710 ) -> Result < bool > {
720- for ( edge_id, ( left_condition , right_condition ) ) in join_conditions. iter ( ) . enumerate ( ) {
711+ for ( edge_id, condition ) in join_conditions. iter ( ) . enumerate ( ) {
721712 let mut left_relation_set = HashSet :: new ( ) ;
722713 let mut right_relation_set = HashSet :: new ( ) ;
723714
724- let left_used_tables = left_condition . used_tables ( ) ?;
715+ let left_used_tables = condition . left . used_tables ( ) ?;
725716 for table in left_used_tables. iter ( ) {
726717 left_relation_set. insert ( self . table_index_map [ table] ) ;
727718 }
728719
729- let right_used_tables = right_condition . used_tables ( ) ?;
720+ let right_used_tables = condition . right . used_tables ( ) ?;
730721 for table in right_used_tables. iter ( ) {
731722 right_relation_set. insert ( self . table_index_map [ table] ) ;
732723 }
@@ -904,7 +895,7 @@ mod tests {
904895 use crate :: plans:: MaterializedCTERef ;
905896 use crate :: plans:: Sequence ;
906897
907- fn bool_constant ( value : bool ) -> ScalarExpr {
898+ fn bool_constant ( value : bool ) -> crate :: ScalarExpr {
908899 ConstantExpr {
909900 span : None ,
910901 value : Scalar :: Boolean ( value) ,
0 commit comments