Skip to content

fix: stop probing at the fetch limit when the hash join build map is empty - #27750

Open
Aaravkhanal wants to merge 2 commits into
apache:mainfrom
Aaravkhanal:codex/hash-join-empty-build-fetch
Open

Aaravkhanal wants to merge 2 commits into
apache:mainfrom
Aaravkhanal:codex/hash-join-empty-build-fetch

Conversation

@Aaravkhanal

@Aaravkhanal Aaravkhanal commented Nov 25, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Closes #27726.

Rationale for this change

A hash join with a pushed-down limit can keep reading probe batches after it has found enough rows when the build map is empty.

What changes are included in this PR?

Finish the output buffer when this path reaches the fetch limit. This flushes buffered rows and stops the stream before it polls the probe input again.

What is the testing strategy for this PR?

The regression test covers right anti and right mark joins, each with an empty build input and an input containing only a NULL key. Each case checks the returned probe values and fails if the join polls the probe again after reaching the limit. All 697 hash-join tests passed locally with the expanded coverage.

Are there any user-facing changes?

With the default configuration, right anti and right mark hash joins with an empty build map stop scanning the probe input once the pushed-down limit is satisfied. The same change applies to right and full hash joins when datafusion.execution.enable_migration_hash_join = false.

Assisted-by: OpenAI Codex

@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Nov 25, 2026

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @Aaravkhanal. The fix matches how the non-empty path already handles LimitReached (stream.rs).

Since #27399, this branch of HashJoinStream runs in fewer cases than the PR description suggests. On the default config, inner, left, right, and full joins go to BatchedJoinProcessor (RegularJoinKind::from_join_type), which already stops at the limit (batched_join_processor.rs). The only join types that emit rows from this empty-map branch are RightAnti and RightMark. Right and Full reach it only with datafusion.execution.enable_migration_hash_join = false (config.rs). The stream isn't deprecated: its module docs say semi, anti, mark, and null-aware joins still use it by default (stream.rs). So the fix is worth having until existence joins move to their own stream (#26361). Could you name these join types in the "Are there any user-facing changes?" section, so readers of the changelog know which queries change?

Co-authored-by: Matt Butrovich <6855576+mbutrovich@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HashJoinExec with a fetch reads its whole probe side when its build-side hash map is empty

2 participants