diff/reel
All reels

sandboxed iframe · 45s loop · 32 KB

Databases

N+1 vs JOIN

The same page, the same data — one round trip or a hundred and one.

Posted Aug 15, 2026 · 4 views

Rendering a list of rows with something attached to each one can cost wildly different amounts depending on how the query is written.

N+1: one query fetches the list, then one more query fires per row. On identical geometry it looks like a machine-gun stream of requests, and the page's cost grows with the number of rows — each one paying full network latency.

JOIN: one query goes out and one result comes back, with the related rows already attached. One round trip, whatever the row count.

The failure is invisible in development, where the database is on localhost and the list has four rows. It is not invisible in production.

Related reels