4 ms·
This is good. SQL templates are usually much faster for database queries than using ORMs.
by tkyjonathan 10y ago
This is good. SQL templates are usually much faster for database queries than using ORMs.
- nathancahill 10y agoI'll take the bait. It's easy to write a slow SQL query, and equally easy to write a fast ORM query. In the long run, for readability and maintainability, ORMs win most of the time. I've rarely found a slow ORM query that couldn't be fixed without resorting to SQL (half the time it's bad indexes, half the time it's doing something un-performant in the ORM). The few times when I do need to force a certain SQL syntax that the ORM won't give me, I drop down to SQL. But doing that doesn't magically make all queries faster.
- svisser 10y ago> In the long run, for readability and maintainability, ORMs win most of the time. It depends. Anyone working on that code now needs to learn the ORM, the SQL and how to let the ORM generate that SQL for anything beyond the basics.
- traviscj 10y agoMy favorite trick is binding a hook in unit test modules that basically runs an "explain q" for every query "q", and asserts that it found an appropriate index to use. Then as long as your unit tests exercise all queries your app needs, you know that your database indices are appropriate for your app's usages.
- Can_Not 10y agoI wish laravel had this and an automated SQL debug comment feature.