Nested-Loop · scanning
R (outer relation, cubes) S (inner relation, spheres)
⚠ Couldn't load the 3D engineThree.js failed to load from the CDN. Check your connection and reload.

Join Algorithm Race: Nested-Loop vs Hash vs Sort-Merge

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.