cloud-fan commented on code in PR #51046:
URL: https://github.com/apache/spark/pull/51046#discussion_r2375370533
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -411,6 +411,18 @@ abstract class Optimizer(catalogManager: CatalogManager)
s.withNewPlan(
if (needTopLevelProject) newPlan else newPlan.child
)
+ case s: Exists =>
+ // Find all the references (columns / attributes) in the child plan
that are needed
+ // by the EXISTS expression.
+ val selectedRefrences =
+ s.plan.output.filter(s.joinCond.flatMap(_.references).contains)
+ val projectOverChild = Project(selectedRefrences, s.plan)
+ val Subquery(newPlan, _) =
+
Optimizer.this.execute(Subquery.fromExpression(s.withNewPlan(projectOverChild)))
+ // At this point we have an optimized subquery plan that we are going
to attach
+ // to this subquery expression. Here we can safely remove any top
level sort
+ // in the plan as tuples produced by a subquery are un-ordered.
+ s.withNewPlan(removeTopLevelSort(newPlan))
Review Comment:
nit: can we create a util function to do this and save duplicated code?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]