cloud-fan commented on code in PR #60376:
URL: https://github.com/apache/spark/pull/60376#discussion_r4547189404
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala:
##########
@@ -380,9 +381,12 @@ trait JoinSelectionHelper extends Logging {
if (canBuildBroadcastLeft(joinType)) BuildLeft else BuildRight
}
- // The side to broadcast by hint, or by size, if any.
+ // The side to broadcast by hint, or by size, if any.
`BroadcastNestedLoopJoinExec` can't build
+ // the left side of a LeftSingle join, so that side never qualifies.
Review Comment:
**Nit (P3):** Choosing the right side here means a non-equi LeftSingle join
whose small outer side alone qualifies for broadcast now broadcasts the
subquery side whatever its size. For example, in `SELECT a, (SELECT id FROM big
WHERE id < l.a) FROM small l` with `small` under
`spark.sql.autoBroadcastJoinThreshold` and `big` over it, `big` is collected to
the driver and broadcast. When `big` exceeds the broadcast size or row limits,
the query still fails, now at broadcast time. The PR description explains the
cheaper alternative and why it isn't taken here: teach
`BroadcastNestedLoopJoinExec` to build the left side of a LeftSingle join,
which would broadcast the small outer side and stream the large one. That is a
fair reason to keep this PR small. But the comment here states only the
executor limitation, so a later reader can't tell that the cost is a known,
deferred one, or which change would lift it, and may take the check as a
permanent rule. The existing `TODO: revisit it.` a
few lines up concerns the left-join build preference in general, not this
case. Could you add a TODO naming the deferred executor change?
```suggestion
// The side to broadcast by hint, or by size, if any.
`BroadcastNestedLoopJoinExec` can't build
// the left side of a LeftSingle join, so that side never qualifies.
// TODO: teach `BroadcastNestedLoopJoinExec` to build the left side of a
LeftSingle join by
// detecting more than one match per left row, so a small outer side can
be broadcast instead
// of a large subquery side.
```
**Verification:**
- **Inspection:** Confirm that the comment at the LeftSingle check in
getNonEquiJoinBuildSide names the deferred change, which is building the left
side of a LeftSingle join in BroadcastNestedLoopJoinExec by detecting more than
one match per left row. Confirm it also says this would let a small outer side
be broadcast instead of a large subquery side, and that the edit changes no
executable 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]