Repository navigation
Labels
PROPOSAL EPICA proposal being discussed that is not yet fully underwayenhancementNew feature or request
Description
Is your feature request related to a problem or challenge?
A perfect hash join is a highly specialized form of a hash join that eliminates a lot of runtime overhead. It can be thought of as a hybrid between a hash join and a direct-lookup array join.
Here are the conditions for this join and the reasons for why they are needed
Single Join Key
- Perfect hash join only works when there is exactly one join key per row.
- Multiple keys would require building composite keys - cannot index into
Integer Key
- Keys must be integers (or convertible to contiguous integer ranges)
- Allows for direct addressing: output[key] = value.
Distinct Values on Build Side
- The build side must have unique keys (no duplicates).
- This ensures a 1:1 mapping from key → value, allowing direct indexing without needing to chain multiple rows in a bucket.
Inner Join
- Perfect hash join works best with inner joins because you only need to store matches.
- Outer joins would require materializing nulls for missing keys, which reintroduces complexity
With perfect hash join:
- determine the minimum and maximum key on the build side.
- Allocate a contiguous array of size max_key - min_key + 1.
- Store each build row at index key - min_key in the array.
during probe phase:
- For each probe key, check if it falls in [min_key, max_key].
- If yes, directly index into the array to find the corresponding row.
- If no, skip (no match).
Describe the solution you'd like
- feat: Add Hash Join benchmarks #17636
- Use existing accumulator to calculate min/max values
- Pass flag to
HashJoinExecto specify if perfect hash join execution is needed- Can check distinct values from the hash table or use existing statistics.
Implement perfect hash join execution.
- Add stream implementation
Describe alternatives you've considered
No response
Additional context
DuckDB's implementation can be seen here:
duckdb/duckdb#1959
Reacted by Nuno Faria and feniljain
Metadata
Metadata
Assignees
Labels
PROPOSAL EPICA proposal being discussed that is not yet fully underwayenhancementNew feature or request
Activity
jonathanc-n commentedon Sep 17, 2025
take
Jefffrey commentedon Sep 20, 2025
@Dandandan should we close #816 as duplicate in favour of this issue?
perfect hash join (#19411)
perfect hash join (apache#19411)