Plan nodes · Joins

Hash Join

Builds a hash table from one input, then probes it with each row of the other.

Reads the inner (second) input into a hash table keyed on the join columns, then streams the outer input through it. Good for large, unsorted inputs with an equality condition. If the hash table does not fit in work_mem (times hash_mem_multiplier), it is split into batches written to temporary files.

What to look for

More than one batch means the hash spilled to disk.

Example

SELECT a.name, count(*) FROM artists a JOIN albums b ON b.artist_id = a.id GROUP BY a.name

6 nodes

Run with EXPLAIN (ANALYZE, BUFFERS, TIMING OFF, SUMMARY OFF) on the sample database, PostgreSQL 19.0. Open it in the EXPLAIN visualizer →

Related

Nested Loop · Hash · Merge Join · Memoize · Materialize