N+1 query
One list query triggers another query for every result.
Use this when A page becomes slower in proportion to the number of displayed rows.
without the term
“The posts page gets slower the more posts there are. The logs show one query for the posts and then one more query for every single post's author. Can you load it more efficiently?”
with the term · How do you ask a model for N+1 query?
Fix the N+1 query on this list. Batch the related reads and show that doubling the rows does not double the query count.
What is N+1 query?
N+1 describes repeated per-record fetching after an initial query. Batching or suitable joins can reduce the round trips.
Why does N+1 query matter when vibe coding?
A generated loop around an ORM call can hide the query count.
How do you do N+1 query?
Trace database calls for a realistic list. Check that query count remains bounded as the list grows.
What goes wrong with N+1 query?
One enormous join replaces the round trips but multiplies the result rows.