0 day streak
8. DatabasesEXPLAIN and joins

EXPLAIN and joins

When you send a SQL query, the database doesn’t run it literally: a planner chooses a strategy, called the query plan, and EXPLAIN shows you that plan as a tree of steps such as scanning a table, using an index, sorting or joining. Joins, which combine rows from two tables that match on some condition, can be done three main ways. A nested loop checks each row of one table against the other, which is great when one side is tiny or indexed. A hash join builds a lookup table from the smaller side and probes it with the larger. A merge join walks two already-sorted inputs side by side. Reading plans is how you find out why a query is slow.

In this lesson: A plan-tree visualizer, and nested-loop, hash and merge join steppers.