-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Incorrect LEFT JOIN evaluation result on OR conditions #11203
Changes from 1 commit
7549e8b
a506bed
9cc111e
17b2d43
68e8838
70bf59f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,8 +424,9 @@ fn push_down_all_join( | |
} | ||
} | ||
|
||
let (on_left_preserved, on_right_preserved) = on_lr_is_preserved(join.join_type)?; | ||
|
||
if !on_filter.is_empty() { | ||
let (on_left_preserved, on_right_preserved) = on_lr_is_preserved(join.join_type)?; | ||
for on in on_filter { | ||
if on_left_preserved && can_pushdown_join_predicate(&on, left_schema)? { | ||
left_push.push(on) | ||
|
@@ -441,11 +442,11 @@ fn push_down_all_join( | |
|
||
// Extract from OR clause, generate new predicates for both side of join if possible. | ||
// We only track the unpushable predicates above. | ||
if left_preserved { | ||
if on_left_preserved { | ||
left_push.extend(extract_or_clauses_for_join(&keep_predicates, left_schema)); | ||
left_push.extend(extract_or_clauses_for_join(&join_conditions, left_schema)); | ||
} | ||
if right_preserved { | ||
if on_right_preserved { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have discussed the conditions, filter predicates and on expression can be pushed down with @ozankabak .
where, for predicates and join conditions flag used is different. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I understand what is different about your suggestion. My understanding of the code is that to breaks the predicates into:
I think the code, as written, does push predicates from the ON clause down correctly when possible. So in other words, I am not sure what changes you are suggesting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could be missing something but it seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For left join, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we wrongly mix join filter predicates and filter predicates into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the clarifications
I agree, but I think this is required for correctness. At least for For example, in this query I am pretty sure it is not correct to push the predicate on SELECT .. FROM A LEFT JOIN B ON (A.a > 5) I think is correct to push predicates on B below (as any non matching rows would have been filtered in the join anyways) SELECT .. FROM A LEFT JOIN B ON (B.b > 5)
Can you help me write an example? I can add it to this PR and then we can handle improving the case in a future PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to add a test case with it. EDIT: Seems it doesn't test against the corner case. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we found one example -- @mustafasrepo will post shortly |
||
right_push.extend(extract_or_clauses_for_join(&keep_predicates, right_schema)); | ||
right_push.extend(extract_or_clauses_for_join(&join_conditions, right_schema)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep_predicates
,join_conditions
are join filter but not predicates from top Filter, we should useon_lr_is_preserved
instead oflr_is_preserved
.