Uh oh!
There was an error while loading. Please reload this page.
[SPARK-41162][SQL] Do not push down anti-join predicates that become ambiguous - #38676
[SPARK-41162][SQL] Do not push down anti-join predicates that become ambiguous#38676EnricoMi wants to merge 4 commits into
Conversation
I did not manage to test this in My approach is This creates plan while this plan would be required to expose the bug (both |
EnricoMi
commented
Nov 16, 2022
Note: |
6599f96 to
08f6ea3CompareEnricoMi
commented
Nov 17, 2022
@wangyum@cloud-fan appreciate your suggestion on how to test this bug in |
wangyum
commented
Nov 18, 2022
@EnricoMi@cloud-fan Could we fix the |
EnricoMi
commented
Nov 18, 2022
Interesting, that sounds like a better solution. I'll look into it. |
Problem is that There is now a second run of rule It is now safe to apply rule This could potentially be done for all operators specifically handled in Deduplicating attributes that are already referenced will break the plan as those references break. https://github.com/G-Research/spark/actions/runs/3498935957/jobs/5862050045 |
0948536 to
c7eaaa2Compare| condition: Option[Expression]) extends UnaryNode { | ||
| require(Seq(Inner, LeftOuter, Cross).contains(joinType), | ||
| require(Seq(Inner, LeftOuter, Cross).contains(joinType match { |
There was a problem hiding this comment.
just needed by sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/DeduplicateRelationsSuite.scala:
val originalQuery = left.lateralJoin(right, UsingJoin(Inner, Seq("a")))
AmplabJenkins
commented
Nov 19, 2022
Can one of the admins verify this patch? |
EnricoMi
commented
Nov 22, 2022
@wangyum@cloud-fan I am not sure if this is the right approach to fix Problem is that |
@wangyum@cloud-fan what do you think about my approach? Do you have a suggestion for a better strategy? |
EnricoMi
commented
Dec 12, 2022
@wangyum@cloud-fan do you consider this issue a correctness bug? |
shardulm94
commented
Dec 17, 2022
I tried looking into this a bit
As @EnricoMi said Similar to the |
EnricoMi
commented
Dec 19, 2022
@shardulm94 you are right, I have created #39131, to keep it separate from this approach, which tries to fix this issue through Thanks for the pointer! |
EnricoMi
commented
Jan 4, 2023
Closed in favour of #39131. |
What changes were proposed in this pull request?
Rule
PushDownLeftSemiAntiJoinshould not push an anti-join below anAggregatewhen the translated (cf.aliasMap) join conditions become ambiguous w.r.t. to both join sides.Why are the changes needed?
This example fails with
distinct(), and succeeds withoutdistinct(), but both queries are identical:With
distinct(), rulePushDownLeftSemiAntiJoincreates a join condition(id#774 + 1) = id#774, which can never be true. This effectively removes the anti-join.Before this PR:
The anti-join is fully removed from the plan.
This is caused by
PushDownLeftSemiAntiJoinadding join condition(id#774 + 1) = id#774:After this PR:
Join condition
id#776 = id#774is still translated into(id#774 + 1) = id#774but recognized as ambiguous to both sides of the prospect join and hence not pushed down. The rule is then not applied any more.The final plan contains the anti-join:
Does this PR introduce any user-facing change?
It fixes correctness.
How was this patch tested?
Unit test.