N+1 query in databases
dev.to·6d·
Discuss: DEV
Flag this post

Table of content

What is N+1 query Analogy: The library Technical example Inefficient and Efficient query Why you should care about the N+1 query problem


What is N+1 query

The N+1 query problem is a database anti-performance pattern, where an application executes one query to fetch a list of items (N items in 1 query) and then makes N additional individual queries to fetch related data for each item in that list(N number of queries). So, in total you are making 101 queries, 1 query to get the list and 100 query to get names of authors.

This results in N+1 queries for what sh…

Similar Posts

Loading similar posts...