dilipbiswal commented on a change in pull request #24344: [SPARK-27440][SQL] 
Optimize uncorrelated predicate subquery
URL: https://github.com/apache/spark/pull/24344#discussion_r285883266
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/subquery.scala
 ##########
 @@ -93,6 +93,21 @@ object SubqueryExpression {
     }.isDefined
   }
 
+  /**
+   * Returns true when an expression contains a correlated IN or correlated 
EXISTS and
+   * false otherwise. An IN is non-correlated only if the left values are 
foldable
+   * and the subquery has no outer references.
+   */
+  def hasCorrelatedInOrExists(e: Expression): Boolean = {
+    e.find {
+      case InSubquery(values, ListQuery(_, children, _, _)) =>
+        values.exists(!_.foldable) || children.nonEmpty
+      case Exists(_, children, _) =>
+        children.nonEmpty
+      case _ => false
+    }.isDefined
+  }
+
 
 Review comment:
   @francis0407 Like wenchen, i can see a source of confusion here. So if we 
have a query like 
   select * from t1 where c1 in (1, 2), we will flag is at correlated, right ? 
I understand what you are doing here :-). But, future caller of this function 
may not understand the subtle difference (since its an utility function) ? What 
do you think ? 

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


With regards,
Apache Git Services

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

Reply via email to