AngersZhuuuu 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_r345633879
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/subquery.scala
##########
@@ -194,6 +258,9 @@ case class PlanSubqueries(sparkSession: SparkSession)
extends Rule[SparkPlan] {
}
val executedPlan = new QueryExecution(sparkSession, query).executedPlan
InSubqueryExec(expr, SubqueryExec(s"subquery#${exprId.id}",
executedPlan), exprId)
+ case expressions.Exists(sub, children, exprId) =>
+ val executedPlan = new QueryExecution(sparkSession, Project(Nil,
sub)).executedPlan
Review comment:
> I checked `PullupCorrelatedPredicates`, and we will add the missing
references.
>
> I don't think `Project(Nil, ...)` can cause problems. People can always
write queries with missing references, e.g. `EXISTS (SELECT a FROM t WHERE t.b
= outer_table.col)`, and the framework must be prepared for it.
With UT below, failed.
```
test("SPARK-29800") {
withTempView("s1", "s2", "s3") {
Seq(1, 3, 5, 7, 9).toDF("id").createOrReplaceTempView("s1")
Seq(1, 3, 4, 6, 9).toDF("id").createOrReplaceTempView("s2")
Seq(3, 4, 6, 9).toDF("id").createOrReplaceTempView("s3")
sql(
"""
| SELECT s1.id FROM s1
| JOIN s2 ON s1.id = s2.id
| WHERE EXISTS (SELECT * from s3 where s3.id = s1.id)
""".stripMargin).show()
}
}
```
----------------------------------------------------------------
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]