The most common performance fault.
WHAT HAPPENS
A list of records is retrieved with one query.
Then, for each, a related record is accessed, issuing another query.
WHAT THAT MEANS
Displaying fifty records issues fifty-one queries.
WHY IT IS EASY TO MISS
It works perfectly with three records in development.
WHAT IT PRODUCES IN PRODUCTION
Slow pages, timeouts and database load.
HOW TO DETECT IT
Count queries per request.
Any page issuing dozens is suspect.
WHAT TO DO
Specify the relationships to load with the initial query.
WHAT ELSE TO DO
Load only the relationships actually used Load only the columns needed Count related records with an aggregate rather than loading them
WHAT TO BE CAREFUL WITH
Loading everything eagerly, which fetches data you do not use.
WHAT TO CHECK
Templates, where relationship access frequently hides.
WHAT TO ADOPT
A tool that reports query count during development.
WHAT TO SET
A limit that raises an error when a request exceeds a query threshold, in development.