leanken commented on a change in pull request #29104:
URL: https://github.com/apache/spark/pull/29104#discussion_r454996484



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/BroadcastNestedLoopJoinExec.scala
##########
@@ -205,6 +226,117 @@ case class BroadcastNestedLoopJoinExec(
     }
   }
 
+  case class NotInSubquerySingleColumnOptimizeParams(
+      buildSideHashSet: mutable.HashSet[AnyRef],
+      isNullExists: Boolean,
+      isBuildRowsEmpty: Boolean)
+
+  private def notInSubquerySingleColumnOptimizeEnabled: Boolean = {
+    if (SQLConf.get.notInSubquerySingleColumnOptimizeEnabled && 
right.output.length == 1) {
+      // buildSide must be single column
+      // and condition must be either of following pattern
+      // or(a=b,isnull(a=b))
+      // or(isnull(a=b),a=b)
+      condition.get match {
+        case _@Or(_@EqualTo(leftAttr: AttributeReference, rightAttr: 
AttributeReference),
+            _@IsNull(_@EqualTo(tmpLeft: AttributeReference, tmpRight: 
AttributeReference)))
+            if leftAttr.semanticEquals(tmpLeft) && 
rightAttr.semanticEquals(tmpRight) =>
+          notInSubquerySingleColumnOptimizeSetStreamedKey(leftAttr, rightAttr)
+          if (notInSubquerySingleColumnOptimizeStreamedKeyIndex != -1) {
+            true
+          } else {
+            logWarning(s"failed to find 
notInSubquerySingleColumnOptimizeStreamedKeyIndex," +
+              s" fallback to leftExistenceJoin.")
+            false
+          }
+        case _@Or(_@IsNull(_@EqualTo(tmpLeft: AttributeReference, tmpRight: 
AttributeReference)),
+            _@EqualTo(leftAttr: AttributeReference, rightAttr: 
AttributeReference))
+            if leftAttr.semanticEquals(tmpLeft) && 
rightAttr.semanticEquals(tmpRight) =>
+          notInSubquerySingleColumnOptimizeSetStreamedKey(leftAttr, rightAttr)
+          if (notInSubquerySingleColumnOptimizeStreamedKeyIndex != -1) {
+            true
+          } else {
+            logWarning(s"failed to find 
notInSubquerySingleColumnOptimizeStreamedKeyIndex," +
+              s" fallback to leftExistenceJoin.")
+            false

Review comment:
       I check on the source code on subquery.scala, found that
   Or(EqualTo(a, b), IsNull(EqualTo(a, b))) will be the only option, there is 
no need to handle two Or pattern. so i remove the duplicate code.
   
   ```
   val inConditions = values.zip(sub.output).map(EqualTo.tupled)
             // To handle a null-aware predicate not-in-subquery in nested 
conditions
             // (e.g., `v > 0 OR t1.id NOT IN (SELECT id FROM t2)`), we 
transform
             // `inConditon` (t1.id=t2.id) into `(inCondition) OR 
ISNULL(inCondition)`.
             //
             // For example, `SELECT * FROM t1 WHERE v > 0 OR t1.id NOT IN 
(SELECT id FROM t2)`
             // is transformed into a plan below;
             // == Optimized Logical Plan ==
             // Project [id#78, v#79]
             // +- Filter ((v#79 > 0) OR NOT exists#83)
             //   +- Join ExistenceJoin(exists#83), ((id#78 = id#80) OR 
isnull((id#78 = id#80)))
             //     :- Relation[id#78,v#79] parquet
             //     +- Relation[id#80] parquet
             val nullAwareJoinConds = inConditions.map(c => Or(c, IsNull(c)))
   ```




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