viirya commented on a change in pull request #24344: [SPARK-27440][SQL]
Optimize uncorrelated predicate subquery
URL: https://github.com/apache/spark/pull/24344#discussion_r276573822
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
##########
@@ -551,3 +552,30 @@ object RewriteCorrelatedScalarSubquery extends
Rule[LogicalPlan] {
}
}
}
+
+/**
+ * This rule rewrites uncorrelated PredicateSubquery expressions such as
Exists.
+ * The uncorrelated Exists can be evaluated using a subplan instead of a
semi-join.
+ * Also, we can use `limit 1` and `select 1` after the subquery to reduce the
result set.
+ * Example:
+ * exists(select b from t where t.a = 2) => exists(select 1 from t where t.a =
2 limit 1)
Review comment:
Can you give a more complete example query for this rewrite? It is
beneficial for readers.
----------------------------------------------------------------
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]