dongjoon-hyun opened a new pull request, #60458:
URL: https://github.com/apache/spark/pull/60458
### What changes were proposed in this pull request?
This PR fixes `InjectRuntimeFilter.isProbablyShuffleJoin` to check whether a
broadcast hash join can build the small side of an equi-join, using
`canPlanAsBroadcastHashJoin`.
`InjectRuntimeFilter` injects a runtime bloom filter when the join is
probably a shuffle join, or when the application side has a shuffle below a
broadcast join (`probablyHasShuffle`). Both use `isProbablyShuffleJoin`, which
assumed a broadcast join whenever either side was small enough to broadcast.
However, a broadcast hash join can build only a side that its join type allows.
For example, a `LEFT OUTER JOIN` cannot build its left side. A shuffle hash
join hint also rules out a size-based broadcast hash join. In these cases,
Spark plans a shuffle join, but the rule skipped the bloom filter.
```scala
- private def isProbablyShuffleJoin(left: LogicalPlan,
- right: LogicalPlan, hint: JoinHint): Boolean = {
- !hintToBroadcastLeft(hint) && !hintToBroadcastRight(hint) &&
- !canBroadcastBySize(left, conf) && !canBroadcastBySize(right, conf)
+ private def isProbablyShuffleJoin(join: Join): Boolean = join match {
+ case ExtractEquiJoinKeys(_, _, _, _, _, _, _, _) =>
!canPlanAsBroadcastHashJoin(join, conf)
+ case Join(left, right, _, _, hint) =>
+ !hintToBroadcastLeft(hint) && !hintToBroadcastRight(hint) &&
+ !canBroadcastBySize(left, conf) && !canBroadcastBySize(right, conf)
}
```
`canPlanAsBroadcastHashJoin` is built on `getBroadcastHashJoinBuildSide`,
which this rule already uses to find the broadcastable plans. A join without
equi-join keys keeps the existing check, because it is not a hash join. It
becomes a broadcast nested loop join or a cartesian product, so its join type
does not decide whether it shuffles.
### Why are the changes needed?
To inject runtime bloom filters into the shuffle joins that the rule missed.
For example, in the following query, the left side is small, but a `LEFT OUTER
JOIN` cannot broadcast it. When `bf2` is too large to broadcast, Spark shuffles
`bf2` for a sort merge join, but no bloom filter prunes `bf2` before the
shuffle.
```sql
SELECT * FROM (SELECT c1 FROM bf1 WHERE a1 = 5) a LEFT JOIN bf2 ON a.c1 =
bf2.c2
```
This has happened since Apache Spark 3.3.0, which added the rule in
SPARK-32268.
### Does this PR introduce _any_ user-facing change?
No, the query results do not change. Spark injects runtime bloom filters
into more shuffle joins, so the query plans of such queries change.
### How was this patch tested?
Pass the CIs with the newly added test case in `InjectRuntimeFilterSuite`,
which fails without this PR. It covers:
- the small left side of a `LEFT OUTER JOIN`
- a `shuffle_hash` hint on the small side of an inner join
- the same `LEFT OUTER JOIN` below a broadcast hash join
(`probablyHasShuffle`)
- a non-equi `LEFT OUTER JOIN` below a broadcast hash join, which is a
broadcast nested loop join and gets no bloom filter
In addition, regenerating the TPC-DS plan stability golden files
(`*PlanStabilitySuite`) changes no file.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
--
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]