wangyum commented on code in PR #40742:
URL: https://github.com/apache/spark/pull/40742#discussion_r1166312550


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/QueryPlanConstraints.scala:
##########
@@ -66,13 +66,13 @@ trait ConstraintHelper {
     val predicates = constraints.filterNot(_.isInstanceOf[IsNotNull])
     predicates.foreach {
       case eq @ EqualTo(l: Attribute, r: Attribute) =>
-        val candidateConstraints = predicates - eq
+        val candidateConstraints = predicates - eq - EqualNullSafe(l, r)

Review Comment:
   For example:
   ```
   Join Inner, (a#0 = a#7)
   :- Project [a#0, a#0 AS xa#3]
   :  +- Join Inner, (a#0 = a#4)
   :     :- LocalRelation <empty>, [a#0, b#1, c#2]
   :     +- LocalRelation <empty>, [a#4, b#5, c#6]
   +- LocalRelation <empty>, [a#7, b#8, c#9]
   ```
   After `InferFiltersFromConstraints`:
   ```
   Join Inner, (a#0 = a#7)
   :- Filter ((a#0 <=> a#0) AND (xa#3 <=> xa#3))
   :  +- Project [a#0, a#0 AS xa#3]
   :     +- Join Inner, (a#0 = a#4)
   :        :- Filter isnotnull(a#0)
   :        :  +- LocalRelation <empty>, [a#0, b#1, c#2]
   :        +- Filter isnotnull(a#4)
   :           +- LocalRelation <empty>, [a#4, b#5, c#6]
   +- Filter isnotnull(a#7)
      +- LocalRelation <empty>, [a#7, b#8, c#9]
   ```
   
   And run `InferFiltersFromConstraints` again. The left side constraints:
   ```
   (a#0 <=> xa#3)
   (xa#3 = a#0)
   (a#0 <=> a#0)
   (xa#3 <=> xa#3)
   ```
   The right side constraints:
   ```
   (isnotnull(a#7))
   ```
   Join condition is:
   ```
   (a#0 = a#7)
   ```
   
   Based on these constraints, the inferred result is:
   ```
   (a#7 <=> xa#3)
   (xa#3 = a#7)
   (a#7 <=> a#7)
   ```
   
   `(a#7 <=> a#7)` is a valid constraints for right side. The result:
   
   ```
   Join Inner, (a#0 = a#7)
   :- Filter ((a#0 <=> a#0) AND (xa#3 <=> xa#3))
   :  +- Project [a#0, a#0 AS xa#3]
   :     +- Join Inner, (a#0 = a#4)
   :        :- Filter isnotnull(a#0)
   :        :  +- LocalRelation <empty>, [a#0, b#1, c#2]
   :        +- Filter isnotnull(a#4)
   :           +- LocalRelation <empty>, [a#4, b#5, c#6]
   +- Filter (a#7 <=> a#7)
      +- Filter isnotnull(a#7)
         +- LocalRelation <empty>, [a#7, b#8, c#9]
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to