Comparison
N+1 queryvsObject-relational mapping
N+1 query
you fetch a list of fifty orders and then the ORM quietly issues fifty more queries, one per order, to load the customer.
A pattern where fetching a collection triggers one additional query per element, usually via lazy-loaded ORM associations. Latency scales with result size instead of staying flat, so the endpoint is fine in development with three rows and terrible in production with three hundred. The fix is an eager load, a join, or a batched second query.
Full entry →Object-relational mapping
you wrote no SQL, and then spent an afternoon reading the SQL it generated to find out why the page was slow.
A library that maps rows to objects and generates the queries in between, usually implementing data mapper or active record plus an identity map and unit of work. It removes an enormous amount of mechanical code and gives back a layer whose performance characteristics are invisible until they are a problem. Every serious user of one ends up learning to read the generated SQL, which is the fair summary of the trade.
Full entry →