← All benchmarksSQL
N+1 query problem: 2,001 queries (47.7 ms) vs one JOIN (2.8 ms)
How much slower is the N+1 query pattern than a JOIN?
With 2,000 authors and 20,000 books in in-process SQLite, loading each author's books one query at a time issued 2,001 queries in 47.7 ms; one JOIN took 2.8 ms. Over a network each query adds a round trip, so production is worse.
Results
| N+1 | 2,001 queries, 47.7 ms |
|---|---|
| JOIN | 1 query, 2.8 ms |
How it was measured
In-process SQLite, best of 5.
SELECT a.name, count(b.id) FROM authors a LEFT JOIN books b ON b.author_id = a.id GROUP BY a.idWhy
One set-based query replaces thousands of round trips.
When this does not apply
In-process SQLite underestimates network cost.
Environment
MacBook Air (Apple silicon, 8 cores), macOS. Measured 2026-10-12.
Source: shorts/demo-ticket/w2/nplus1.py in my content-engine repository. Treat any single run as a direction; re-run it on your hardware.
Related
By Josué Barros, senior software engineer (full-stack, data and AI).