-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-45009][SQL] Decorrelate predicate subqueries in join condition #42725
[SPARK-45009][SQL] Decorrelate predicate subqueries in join condition #42725
Conversation
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add test cases for other join types: right, full, semi, anti
Looks pretty good overall! CC @agubichev
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala
Outdated
Show resolved
Hide resolved
@@ -55,7 +55,8 @@ abstract class Optimizer(catalogManager: CatalogManager) | |||
Set( | |||
"PartitionPruning", | |||
"RewriteSubquery", | |||
"Extract Python UDFs") | |||
"Extract Python UDFs", | |||
"Infer Filters") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Infer Filters" is not inherently idempotent. We need to exclude it from the idempotency check so that tests will pass.
Looking for reviews! @cloud-fan @sigmod |
Pinging for reviews! @allisonwang-db @cloud-fan |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
Outdated
Show resolved
Hide resolved
@cloud-fan I think the build is failing because of unrelated failing tests -- timeouts for 1:
2:
|
yea they are unrelated, thanks, merging to master! |
…tion of predicate subqueries in join condition which reference both join child ### What changes were proposed in this pull request? This is a follow up PR for #42725, which decorrelates predicate subqueries in join conditions. I forgot to add the error class definition for the case where the subquery references both join children, and test cases for it. ### Why are the changes needed? To show a clear error message when the condition is hit. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added SQL test and golden files. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #46708 from andylam-db/follow-up-decorrelate-subqueries-in-join-cond. Authored-by: Andy Lam <andy.lam@databricks.com> Signed-off-by: Gengliang Wang <gengliang@apache.org>
What changes were proposed in this pull request?
Pulling up correlated subquery predicates in Joins, and re-writing them into ExistenceJoins if they are not pushed down into the join inputs.
Why are the changes needed?
This change allows correlated IN and EXISTS subqueries in join condition. This is valid SQL that is not yet supported by Spark SQL.
Does this PR introduce any user-facing change?
Yes, previously unsupported queries become supported.
How was this patch tested?
Added SQL tests for IN and EXISTS in join conditions, and crossed-check correctness with postgres (except for ANTI joins, which are not supported in postgres).
Permutations of the tests: