Join Algorithm Race: Nested-Loop vs Hash vs Sort-Merge
Watch a database query planner's three classic join algorithms — nested-loop, hash join, and sort-merge join — execute side by side on two relations in 3D, with live comparison and I/O counters showing why the optimizer picks one over another.
Every relational database query with a JOIN clause compiles down to one of a handful of physical join algorithms, and the choice matters enormously for performance. This simulation lays out two relations, R and S, as rows of 3D tuples and steps through the exact scanning behaviour of nested-loop join, hash join, and sort-merge join — the three algorithms every SQL query planner chooses between. Watch the comparison counter climb quadratically under nested-loop while hash and sort-merge stay roughly linear, adjust the size of each relation and the key domain to see when each algorithm wins, and step through execution one comparison at a time to see exactly how a build phase, a probe phase, or a two-pointer merge sweep actually works underneath an EXPLAIN plan.
This simulation explores the design and management of databases – systems for storing and retrieving information. It demonstrates how relational database models can be used to organize data and support complex queries.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install