What Is Eager Loading?
Eager loading retrieves an object and its specified related records together in one query or a small fixed number of queries. The associations are loaded before they are accessed, rather than on demand. It is the standard remedy for the N+1 query problem caused by lazy loading in a loop.
Why it matters
Pulling related rows in one pass collapses many small queries into a single efficient one. Used wrongly it can over-fetch data, so it trades extra payload for fewer round trips.
Related guides
What Is Lazy Loading in Data Access?Lazy loading defers fetching related data until it is actually accessed, avoiding upfront queries for associa…
What Is an N+1 Query?An N+1 query is a performance problem where fetching a list runs one query, then one extra query per row to l…
What Is a Query Plan?A query plan is the step-by-step strategy a database chooses to execute a SQL statement, including which inde…