# Sort-merge join

Glossary, read 10 Nov 2026

**The short answer.** A sort-merge join sorts both sides of a join on the join key and then walks the two sorted streams together. It is Spark's default for large equi-joins, but both sides are shuffled and sorted first, which makes it a common source of long stages.

Sort and shuffle are the work that native-engine and hardware vendors say they take over. The Databricks post below shows JVM code generation helping hash join far more than sort-merge join.

The MERGE join hint asks Spark for this strategy. See [shuffle](/glossary/shuffle/) and [spill](/glossary/spill/) for the costs around it.

## A sourced example

In the Databricks engineering post on Spark 2.0, whole-stage code generation cut hash join cost per row from 115 ns to 4.0 ns, but sort-merge join only moved from 750 ns to 700 ns.

## Sources

- Databricks blog: Apache Spark as a Compiler (May 23, 2016): https://www.databricks.com/blog/2016/05/23/apache-spark-as-a-compiler-joining-a-billion-rows-per-second-on-a-laptop.html (read 10 Nov 2026)

Last reviewed 10 Nov 2026. Canonical: https://sparkaccelerationcompare.com/glossary/sort-merge-join/
