09 - Parallel Hash Join Algorithms

202406232045
Status: #idea
Tags: CMU Advanced Database Systems

09 - Parallel Hash Join Algorithms

Dynamic Scaling vs Work Stealing

Hashing vs Sort-Merge

Pasted image 20240623210049.png

Join Algorithm Design Goals

Goals mater whether the DBMS is using a hardware-conscious vs hardware-oblivious algorithm for joins

  1. Minimize synchronization
    • Avoid taking latches during execution
  2. Minimize memory access cost
    • Ensure data is always local to worker thread
      • Ideally in L1, L2. Worst case in L3 (common to all cores)
      • Should not be in a different NUMA region
    • Increase cache utilization by reusing data when its in cache
    • Factors that affect cache misses
      • Cache + TLB capacity
        • Using a lot of lines can lead to line not being in TLB
      • Locality (temporal and spatial)
    • Non-random access (Scan)
      • Clustering data to a cache line
      • Execute maximum number of operations per cache line
    • Random access (Lookups)
      • Partition data to fit in cache + TLB during the build/probe side of the join
      • Involves more work, but the number of cycles is reduced

Hash Join

  1. Partition (optional)
    • Divide the tuples of R and S into disjoint subsets based on a hast of the join key
  2. Build
    • Scan relation R and create a hash table on join key
  3. Probe
    • For each tuple in S, lookup its join key in hash table for R. If match is found, output combined tuple

Partition Phase

Build Phase

For each tuple, hash the join key for that tuple and add it to the appropriate bucket in the hash table

Hash Tables

Design decision 1: Hash Function
Design decision 2: Hashing Scheme
Note

We do not want to use a crpytographic hash function for our join algorithm

Attention

Hashes we like: CRC32 (good for integers), XXHash, FarmHash (last one unsure)?

Hashing Schemes

Hash Table Contents

Probe Phase

For each tuple in S,

  1. hash its join key
  2. check for a match in the bucket in HTR

Optimization: Bloom filter

Benchmarks

Info

Join operator only takes 10% of the total query time, making it not the most important

Note

SAHA from ClickHouse is an extremely performant HT for strings

Attention

Partition-based joins outperform no-partition algorithms in most settings, but it is non-trvial to tune it
Most DBMS's pick one hash join and does not try to be adaptive


References

  1. Slides