cloud-fan commented on a change in pull request #26437: [SPARK-29800][SQL] Plan 
non-correlated Exists 's subquery in PlanSubqueries
URL: https://github.com/apache/spark/pull/26437#discussion_r362454717
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/finishAnalysis.scala
 ##########
 @@ -52,6 +52,20 @@ object ReplaceExpressions extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * Rewrite non correlated exists subquery to use ScalarSubquery
+ *   WHERE EXISTS ( SELECT A FROM TABLE B WHERE COL1 > 10)
+ * will be rewrite to
+ *   WHERE (SELECT A FROM TABLE B WHERE COL1 > 1 LIMIT 1) IS NOT NULL
+ */
+object RewriteNonCorrelatedExists extends Rule[LogicalPlan] {
+  override def apply(plan: LogicalPlan): LogicalPlan = plan 
transformAllExpressions {
+    case exists: Exists if exists.children.isEmpty &&
+      !SubqueryExpression.hasInOrCorrelatedExistsSubquery(exists) =>
 
 Review comment:
   this check is not needed.

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