Log the SQL Your ORM Actually Sends Before You Tune Anything
An ORM writes SQL for you, and the SQL it writes is frequently not the SQL you pictured: extra columns, extra joins, a query fired inside a template loop, or the same lookup repeated once per row. Every ORM can print the statements it sends with timings, and a query-count toolbar or middleware shows them per request. Tuning an ORM call you have never seen the SQL for is guessing, and guesses usually add an index nothing will use.
Questions this Concept answers
- Why is tuning an ORM call without reading its SQL usually guesswork?
Logging the Raw SQL Behind Eloquent Queries in Laravel with toSql and the Query Log
An object-relational mapper (ORM) builds SQL statements from a chained query-builder expression, so the SQL actually sent to the database is hidden from the developer and must be inspected to be veri…