@@ -320,10 +320,8 @@ fn can_evaluate_as_join_condition(predicate: &Expr) -> Result<bool> {
320320/// * do nothing.
321321fn extract_or_clauses_for_join < ' a > (
322322 filters : & ' a [ Expr ] ,
323- schema : & ' a DFSchema ,
323+ schema_cols : & ' a HashSet < Column > ,
324324) -> impl Iterator < Item = Expr > + ' a {
325- let schema_columns = schema_columns ( schema) ;
326-
327325 // new formed OR clauses and their column references
328326 filters. iter ( ) . filter_map ( move |expr| {
329327 if let Expr :: BinaryExpr ( BinaryExpr {
@@ -332,8 +330,8 @@ fn extract_or_clauses_for_join<'a>(
332330 right,
333331 } ) = expr
334332 {
335- let left_expr = extract_or_clause ( left. as_ref ( ) , & schema_columns ) ;
336- let right_expr = extract_or_clause ( right. as_ref ( ) , & schema_columns ) ;
333+ let left_expr = extract_or_clause ( left. as_ref ( ) , & schema_cols ) ;
334+ let right_expr = extract_or_clause ( right. as_ref ( ) , & schema_cols ) ;
337335
338336 // If nothing can be extracted from any sub clauses, do nothing for this OR clause.
339337 if let ( Some ( left_expr) , Some ( right_expr) ) = ( left_expr, right_expr) {
@@ -421,6 +419,10 @@ fn push_down_all_join(
421419 // 3) should be kept as filter conditions
422420 let left_schema = join. left . schema ( ) ;
423421 let right_schema = join. right . schema ( ) ;
422+
423+ let left_schema_columns = schema_columns ( left_schema. as_ref ( ) ) ;
424+ let right_schema_columns = schema_columns ( right_schema. as_ref ( ) ) ;
425+
424426 let mut left_push = vec ! [ ] ;
425427 let mut right_push = vec ! [ ] ;
426428 let mut keep_predicates = vec ! [ ] ;
@@ -467,26 +469,38 @@ fn push_down_all_join(
467469 // Extract from OR clause, generate new predicates for both side of join if possible.
468470 // We only track the unpushable predicates above.
469471 if left_preserved {
470- left_push. extend ( extract_or_clauses_for_join ( & keep_predicates, left_schema) ) ;
471- left_push. extend ( extract_or_clauses_for_join ( & join_conditions, left_schema) ) ;
472+ left_push. extend ( extract_or_clauses_for_join (
473+ & keep_predicates,
474+ & left_schema_columns,
475+ ) ) ;
476+ left_push. extend ( extract_or_clauses_for_join (
477+ & join_conditions,
478+ & left_schema_columns,
479+ ) ) ;
472480 }
473481 if right_preserved {
474- right_push. extend ( extract_or_clauses_for_join ( & keep_predicates, right_schema) ) ;
475- right_push. extend ( extract_or_clauses_for_join ( & join_conditions, right_schema) ) ;
482+ right_push. extend ( extract_or_clauses_for_join (
483+ & keep_predicates,
484+ & right_schema_columns,
485+ ) ) ;
486+ right_push. extend ( extract_or_clauses_for_join (
487+ & join_conditions,
488+ & right_schema_columns,
489+ ) ) ;
476490 }
477491
478492 // For predicates from join filter, we should check with if a join side is preserved
479493 // in term of join filtering.
480494 if on_left_preserved {
481495 left_push. extend ( extract_or_clauses_for_join (
482496 & on_filter_join_conditions,
483- left_schema ,
497+ & left_schema_columns ,
484498 ) ) ;
485499 }
486500 if on_right_preserved {
487501 right_push. extend ( extract_or_clauses_for_join (
488502 & on_filter_join_conditions,
489- right_schema ,
503+ & right_schema_columns ,
490504 ) ) ;
491505 }
492506
0 commit comments