Hash Join Build, Probe, and Partition Spill

Separate the build and probe phases of an equijoin and account for memory limits, collisions, and skew.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. A bucket identifies candidates, not all matches
  2. Partition both sides when the build does not fit

A bucket identifies candidates, not all matches

Build a hash table from one input using join keys, retaining all matching rows for repeated keys under bag semantics. For every probe row, select its bucket and confirm key equality for candidate matches. If three build rows and two probe rows share a key, that key emits six row pairs even with ideal constant-time hashing. Building the smaller input often saves memory, subject to available properties and row widths.

Partition both sides when the build does not fit

A partitioned hash join sends the same key to the same partition on both sides, then processes matching partitions separately. A heavy key can still make one partition too large and increase output work. Extra passes must be included in a cost estimate. Join cardinalities identify the size of the output, and merge joins exploit ordering when it is cheaply available.[1][2]

References

  1. CMU 15-445/645, Introduction to Database Systems: Lectures ↩
  2. PostgreSQL Global Development Group, PostgreSQL Documentation ↩