[SPARK-58485] [SQL] Broadcast hash joins with scalar subquery as join key - #57811
Open
VindhyaG wants to merge 1 commit into
Open
[SPARK-58485] [SQL] Broadcast hash joins with scalar subquery as join key#57811VindhyaG wants to merge 1 commit into
VindhyaG wants to merge 1 commit into
Conversation
VindhyaG
marked this pull request as draft
August 6, 2026 04:28
VindhyaG
force-pushed
the
SPARK-58485
branch
4 times, most recently
from
August 6, 2026 09:42
8f2b199 to
6d393ea
Compare
VindhyaG
marked this pull request as ready for review
August 6, 2026 13:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Broadcast hash join fails with "Subquery has not finished" when the join key contains an uncorrelated scalar subquery.
Rootcause provided bu the the reporter :
ExtractEquiJoinKeys accepts a join key containing an uncorrelated scalar subquery (it has no references, so canEvaluate passes for either side), and the key lands in HashedRelationBroadcastMode(key: Seq[Expression]).
Scalar subqueries are normally started and awaited by SparkPlan.prepareSubqueries and waitForSubqueries, which discover them through QueryPlan.expressions. That walk only surfaces Expression, Option and Iterable constructor arguments (src).
BroadcastMode is an opaque case class, so the subquery inside mode.key is never registered or awaited on the exchange node.
The broadcast thread then evaluates/code-generates the un-updated execution.ScalarSubquery and hits the require(updated) guard (src). The join node's own waitForSubqueries does see its leftKeys/rightKeys, but has no happens-before relationship with the broadcast thread, which doPrepare launches eagerly.
What changes were proposed in this pull request?
Register the HashedRelationBroadcastMode key and wait for the subqueries to be finished before triggering transform.
Since, registering the key to the expressions was the most simple with least changes in the architecture went with that solution out of all the solutions suggested.
Why are the changes needed?
Does this PR introduce any user-facing change?
No
How was this patch tested?
Tested the changes locally with the code provided in the bug and UT.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: GPT 5.5