cloud-fan commented on a change in pull request #29104:
URL: https://github.com/apache/spark/pull/29104#discussion_r458090887



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala
##########
@@ -388,3 +390,36 @@ object PhysicalWindow {
     case _ => None
   }
 }
+
+object ExtractSingleColumnNullAwareAntiJoin extends JoinSelectionHelper with 
PredicateHelper {
+
+  // SingleColumn NullAwareAntiJoin
+  // streamedSideKeys, buildSideKeys
+  // currently these two return Seq[Expression] should have only one element
+  private type ReturnType = (Seq[Expression], Seq[Expression])
+
+  /**
+   * See. [SPARK-32290]
+   * LeftAnti(condition: Or(EqualTo(a=b), IsNull(EqualTo(a=b)))
+   * will almost certainly be planned as a Broadcast Nested Loop join,
+   * which is very time consuming because it's an O(M*N) calculation.
+   * But if it's a single column case, and buildSide data is small enough,
+   * O(M*N) calculation could be optimized into O(M) using hash lookup instead 
of loop lookup.
+   */
+  def unapply(join: Join): Option[ReturnType] = join match {
+    case Join(left, right, LeftAnti,
+      Some(Or(equalTo @ EqualTo(leftAttr: AttributeReference, rightAttr: 
AttributeReference),
+        IsNull(EqualTo(tmpLeft: AttributeReference, tmpRight: 
AttributeReference)))), _)
+        if SQLConf.get.nullAwareAntiJoinOptimizeEnabled &&
+          leftAttr.semanticEquals(tmpLeft) && 
rightAttr.semanticEquals(tmpRight) &&
+          canBroadcastBySize(right, SQLConf.get) &&

Review comment:
       do we need this check? If the right side is not small and we don't apply 
this optimization, Spark still does a broadcast nested loop join and force to 
broadcast.




----------------------------------------------------------------
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.

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