Skip to content
Databases in Practice

What is N+1 Query Problem?

Fetching a list with one query then one extra query per row for its relations — 1 plus N round trips. ORMs make it easy to write; batching, joins, or dataloaders collapse it to a constant handful.

Example

A project list page queries every project, then fires one follow-up query per project for owner profiles; a single join through Drizzle relations returns the same page in two round trips.

What people get wrong

Trusting tiny seed data to reveal query shape. Small tables hide N+1 while production-sized lists expose it, so test pagination with realistic volumes.

Frequently asked questions

How do I spot an N+1 query?

Watch request logs for repeated identical queries differing only by id. One list fetch followed by dozens of single-row lookups is the signature pattern.

Do joins always fix N+1?

Not always, but batching does: joins, grouped IN queries, or dataloader batching all collapse N round trips into a constant few. Measure before and after.

Sources

Browse all Databases in Practice terms →