You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Daniel Tenedorio (Jira)" <ji...@apache.org> on 2026/05/21 21:08:00 UTC

[jira] [Assigned] (SPARK-56977) Respect User Specified JoinType for NEAREST BY Join

     [ https://issues.apache.org/jira/browse/SPARK-56977?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Tenedorio reassigned SPARK-56977:
----------------------------------------

    Assignee: Zhidong Qu

> Respect User Specified JoinType for NEAREST BY Join
> ---------------------------------------------------
>
>                 Key: SPARK-56977
>                 URL: https://issues.apache.org/jira/browse/SPARK-56977
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 4.2.0
>            Reporter: Zhidong Qu
>            Assignee: Zhidong Qu
>            Priority: Major
>              Labels: pull-request-available
>
> The original implementation of NEAREST BY JOIN hardcoded the synthetic join to `LeftOuter` and justified it on the grounds that `LEFT OUTER` and `INNER` are equivalent for an unconditioned join when the right side is non-empty, and `Generate(outer = false)` would drop unwanted rows for INNER when right is empty. While correct in result, this:             
>  * `INNER NEAREST BY` cannot be planned as a Cartesian product. Spark's strategy picks `CartesianProductExec` only for `Inner` joins with no condition; an unconditioned `LeftOuter` join falls back to `BroadcastNestedLoopJoin`, which tries to broadcast the right side. When the right relation is large, the broadcast either OOMs or exceeds `spark.sql.autoBroadcastJoinThreshold` and the planner is left with no good option. `CartesianProductExec` partitions both sides and streams pairs, so it scales naturally with right-side size. Respecting the user's `INNER` join type re-enables this strategy for the common `INNER NEAREST BY` case.
>  * Makes the EXPLAIN output misleading for `INNER NEAREST BY` (shows `LeftOuter` in the underlying join even though the user wrote `INNER`).
>  * Produces a row per left input when `right` is empty under `INNER`, only to drop those rows later via `Generate(outer = false)` and the `size(matches) > 0` filter -- extra work that respecting `joinType` avoids at the source.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org