Skip to content

Commit 17b2d43

Browse files
committed
Don't push join filter predicates into join_conditions
1 parent 9cc111e commit 17b2d43

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎datafusion/optimizer/src/push_down_filter.rs‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ fn push_down_all_join(
424424
}
425425
}
426426

427+
let mut on_filter_join_conditions = vec![];
427428
let (on_left_preserved, on_right_preserved) = on_lr_is_preserved(join.join_type)?;
428429

429430
if !on_filter.is_empty() {
@@ -435,22 +436,37 @@ fn push_down_all_join(
435436
{
436437
right_push.push(on)
437438
} else {
438-
join_conditions.push(on)
439+
on_filter_join_conditions.push(on)
439440
}
440441
}
441442
}
442443

443444
// Extract from OR clause, generate new predicates for both side of join if possible.
444445
// We only track the unpushable predicates above.
445-
if on_left_preserved {
446+
if left_preserved {
446447
left_push.extend(extract_or_clauses_for_join(&keep_predicates, left_schema));
447448
left_push.extend(extract_or_clauses_for_join(&join_conditions, left_schema));
448449
}
449-
if on_right_preserved {
450+
if left_preserved {
450451
right_push.extend(extract_or_clauses_for_join(&keep_predicates, right_schema));
451452
right_push.extend(extract_or_clauses_for_join(&join_conditions, right_schema));
452453
}
453454

455+
// For predicates from join filter, we should check with if a join side is preserved
456+
// in term of join filtering.
457+
if on_left_preserved {
458+
left_push.extend(extract_or_clauses_for_join(
459+
&on_filter_join_conditions,
460+
left_schema,
461+
));
462+
}
463+
if on_right_preserved {
464+
right_push.extend(extract_or_clauses_for_join(
465+
&on_filter_join_conditions,
466+
right_schema,
467+
));
468+
}
469+
454470
if let Some(predicate) = conjunction(left_push) {
455471
join.left = Arc::new(LogicalPlan::Filter(Filter::try_new(predicate, join.left)?));
456472
}
@@ -460,6 +476,7 @@ fn push_down_all_join(
460476
}
461477

462478
// Add any new join conditions as the non join predicates
479+
join_conditions.extend(on_filter_join_conditions);
463480
join.filter = conjunction(join_conditions);
464481

465482
// wrap the join on the filter whose predicates must be kept, if any

0 commit comments

Comments
 (0)