Repository navigation
perf(hash-join): Redesign hash table with contiguous match storage - #27401
Closed
2010YOUY01 wants to merge 3 commits into
Closed
2010YOUY01 wants to merge 3 commits into
2010YOUY01 wants to merge 3 commits into
Conversation
2010YOUY01
marked this pull request as draft
November 13, 2026 08:23
Port the hash-table change from PR apache#27401 onto the current regular-stream refactor. Preserve its limit/coalescing behavior and prepared-build ownership, and retain the legacy index for existence joins.
2010YOUY01
force-pushed
the
redesign-physical-hash-table
branch
from
November 16, 2026 12:06
ffea489 to
e04da7b
Compare
2010YOUY01
added a commit
to 2010YOUY01/arrow-datafusion
that referenced
this pull request
Nov 20, 2026
…th (apache#27399) ## Which issue does this PR close? Step 1 toward: - apache#27398 Part of: - apache#26225 - apache#26361 ## Rationale for this change This PR is step 1 of apache#27398, a structural cleanup of Hash Join to prepare for apache#27401 (physical HT redesign, with 8 queries in the `hj` benchmark achieving >3x speedups). The goal is to make Hash Join easier to understand, review, and optimize. This PR focuses on the execution structure without changing the physical hash table representation. ### Why the cleanup? The existing Hash Join implementation has two major architectural issues: 1. **Regular and existence joins share the same execution path.** It's better to split them to support logic/optimizations specific to each. 2. **Everything is mixed into one layer.** Low-level physical operations are mixed with high-level execution control flow. This makes PRs hard to review: even a change that only touches one layer can appear to be a deep architectural change. The ideal design has three layers (see [apache#27398](apache#27398)): ```text RegularHashJoinStream (execution state machine) | BatchedJoinProcessor (lookup -> filter -> output) | JoinIndexMap (physical hash table / index) ``` This PR establishes the first two layers. The `JoinIndexMap` abstraction and physical redesign are deferred to [apache#27401](apache#27401). For deeper rationale, see: - [apache#26225: Refactor Operators for Maintainability](apache#26225) - [apache#26361: Split Hash Join into regular/existence streams](apache#26361) ## What changes are included in this PR? There are only **two key points** to understand this PR: 1. **Split out the regular Hash Join execution path** (Inner/Left/Right/Full joins). - This is an incremental migration: the existing implementation is preserved as a fallback. - Existence joins continue using the existing path. Once both paths have been migrated, the old implementation can be removed. 2. **Establish `BatchedJoinProcessor` as the main execution layer.** - See the code comments for details. - This separation makes execution control flow easier to reason about independently of the low-level lookup implementation. ### Suggested review order It's easier to read the diff in this order: 1. **Migration configuration:** `enable_migration_hash_join`. When `true`, regular joins use the new path; otherwise, they use the existing implementation. Existence joins always use the existing path. The option defaults to `true`, since the new path covers the existing regular-join functionality. It's planned to keep it for just one release to guard against major bugs, as we did in [apache#22710](apache#22710). 2. **Execution state machine:** `datafusion/physical-plan/src/joins/hash_join/regular_join.rs`. Start with `RegularHashJoinStream::into_stream`, which is the entry point for the entire execution. 3. **Main execution layer:** `datafusion/physical-plan/src/joins/hash_join/batched_join_processor.rs`. Start with the documentation on `BatchedJoinProcessor`, which explains its responsibilities and input/output contract with a concrete example. 4. **...and follow along.** ## What is the testing strategy for this PR? Existing tests are reused. Major join fuzz tests are exercised with both `enable_migration_hash_join=true` and `enable_migration_hash_join=false` to cover the new and legacy implementations during migration. ## Are there any user-facing changes? This PR adds `datafusion.execution.enable_migration_hash_join` (default: `true`). It enables the refactored implementation for inner, left, right, and full hash joins. Setting it to `false` restores the legacy implementation as a temporary workaround for bugs. See issue for details: apache#26361 The option and legacy fallback will be removed once the migration is complete; the current plan is to retain them for one release. --------- Co-authored-by: Matt Butrovich <mbutrovich@users.noreply.github.com>
This was referenced Nov 24, 2026
Member
Author
|
replaced by #27746 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fork CI setup: For pull requests from a fork to
main, enable workflows in your fork's Actions tab before you push.See the fork CI setup guide.
Which issue does this PR close?
Step 2 of
This PR builds on top of #27399, commit 3 is for this PR. Needs rebase after 1st PR is merged.
Rationale for this change
See #27398 for details
hjbenchmark result:What changes are included in this PR?
To read the diff, there are only 3 key points (all explained in #27398)
BatchedJoinProcessorandJoinIndexMapThen read in order:
regular_join.rs,into_stream()BatchedJoinProcessorBatchedJoinProcessorinner probing implementation withJoinIndexMapJoinIndexMapimplements the new contiguous match storage HT layoutWhat is the testing strategy for this PR?
Are there any user-facing changes?