SQL Server Interview Question #284
What is the N+1 query problem?
ASP.NET Core, EF Core & SQL Server Real-World Scenarios Senior Advanced
Detailed Explanation
The N+1 problem occurs when an application executes one query to load a set of parent records and then executes an additional query for each parent to load related data.
For 100 parent rows, this can produce 101 database queries. Network round trips and repeated database work can make this much slower than an appropriately designed query.
Solutions include projections, appropriate eager loading, explicit batch queries, or redesigning the data-access pattern. The correct approach depends on how much related data is actually required.