May 2025
Intermediate to advanced
270 pages
6h 55m
English
Of all the issues in database access, one is particularly notorious. Performance monitoring services give it special attention; it’s even used as a common question in software engineering interviews. This problem is the n+1 query problem. It is particularly important if, as with Rails, we use an ORM. In this section, you’ll learn what n+1s are and how to detect them, and you’ll learn techniques to avoid them.
N+1s arise when trying to fetch an N amount of records in a specific and highly inefficient way: instead of fetching all of them in one query, you go about fetching them one by one, thereby ending up executing N queries. Running SELECT * FROM movies WHERE ID IN (1, 3, 4, 5, 6, ...
Read now
Unlock full access