← Graph

N+1 Queries as a Feature on SQLite

concept 1 connections

Argument Stephen Margheim advances in the Yippee talk: on an embedded engine like SQLite, where an indexed read from the in-memory cache has effectively zero latency, N+1 queries become a feature rather than a bug. Simpler queries are easier to cover with indexes, keep a much larger fraction of queries on the 'hot path' of the DB engine's cache, and eliminate the HTTP/IPC/serialization overhead that makes N+1 painful on Postgres/MySQL. A request can comfortably execute 200 queries at two-nanosecond granularity and still be faster overall because index- and cache-hit rates go up. This reframing unlocks putting data fetching next to data usage (e.g. inside views) because you no longer need to police P50 latency via query consolidation.

category
pattern
about
N+1 Queries as a Feature on SQLite concept
Stephen devotes several minutes to arguing that with SQLite, N+1s become a feature.

Provenance

Read by
1 extraction