Skip to content

[EPIC]: Perfect Hash Join #17635

Closed

Description

@jonathanc-n

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 HashJoinExec to 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

Activity

  1. added
    enhancement
    on Sep 17, 2025
  2. jonathanc-n commented on Sep 17, 2025

    @jonathanc-n
    ContributorAuthor

    take

  3. Jefffrey commented on Sep 20, 2025

    @Jefffrey
    Contributor

    @Dandandan should we close #816 as duplicate in favour of this issue?

  4. added
    PROPOSAL EPIC
    on Nov 24, 2025
  5. added a commit that references this issue on Jan 9, 2026
    c98fa56
  6. added a commit that references this issue on Mar 24, 2026
    8d8728b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PROPOSAL EPICenhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions