Skip to content

[SPARK-56065][SQL] Add AQE fallback from failed broadcast joins to shuffle joins#54925

Open
sunchao wants to merge 7 commits intoapache:masterfrom
sunchao:SPARK-56065
Open

[SPARK-56065][SQL] Add AQE fallback from failed broadcast joins to shuffle joins#54925
sunchao wants to merge 7 commits intoapache:masterfrom
sunchao:SPARK-56065

Conversation

@sunchao
Copy link
Member

@sunchao sunchao commented Mar 20, 2026

What changes were proposed in this pull request?

This PR adds an opt-in AQE fallback path for broadcast join failures caused by broadcast table size/row limits.

When spark.sql.adaptive.broadcastJoin.fallbackToShuffle.enabled is enabled, AQE catches qualifying broadcast stage failures and retries adaptive replanning with broadcast joins disabled, so the query can proceed with shuffle-based joins (for example SMJ/SHJ) instead of failing immediately.

The change also includes safety checks to avoid repeatedly retrying the same failed broadcast relation, and test coverage in AdaptiveQueryExecSuite.

Why are the changes needed?

Today, a query can fail if a planned broadcast side exceeds runtime broadcast limits, even though a shuffle join strategy could still complete successfully.

This PR provides a controlled fallback path to improve robustness for those cases while keeping existing behavior unchanged by default.

Does this PR introduce any user-facing change?

Yes.

A new SQL config is added:

  • spark.sql.adaptive.broadcastJoin.fallbackToShuffle.enabled (default: false)

When enabled, queries that would otherwise fail due to broadcast table row/size limits may instead continue with shuffle-based joins. When disabled, existing behavior remains unchanged.

How was this patch tested?

  • Added/updated unit tests in sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/AdaptiveQueryExecSuite.scala, including:
    • fallback enable/disable behavior
    • preserving required input broadcast exchange behavior
    • rejecting fallback replans that still contain the failed broadcast relation
  • Ran AQE adaptive query test coverage relevant to the new fallback path.
  • Manually validated with real jobs that the plan can transition from initial BHJ to final SMJ under AQE when fallback is enabled.

Was this patch authored or co-authored using generative AI tooling?

Yes, Codex 5.3 High with a lot of harnessing

buildConf("spark.sql.adaptive.broadcastJoin.fallbackToShuffle.enabled")
.doc("When true, adaptive execution retries with broadcast joins disabled if a broadcast " +
"query stage fails because it exceeds broadcast table row or size limits.")
.version("3.5.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? If you want to backport this to branch-3.5, it should be 3.5.9 instead of 3.5.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha thanks @dongjoon-hyun . I was able to update this. Our internal implementation is on branch-3.5 and I ported it for master

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good improvement for 4.2.0, doesn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants