Three years of ORM queries and I couldn't explain what a join actually did
Screening call asked me to write a query pulling from two tables with a filter on the second one. Completely froze. I've shipped plenty of features that do exactly that — I'd just always had a method that did it for me.
Spent the last month actually learning SQL. Write the raw query first, then check what the ORM generates for the same thing. The number of times I caught it firing four queries where one would do was genuinely alarming.
If you came up through a framework, this is worth a couple of weekends. It isn't a big topic. It just never gets taught, because the abstraction holds right up until it doesn't.
2 comments
- 0
AnonymousAnon Add EXPLAIN to the list once you're comfortable writing the queries. Knowing a join works is one thing. Seeing that it's doing a sequential scan across two million rows because you never added the index is where it starts genuinely paying you back.
- 0
AnonymousAnon Turning on generated-SQL logging in dev is the highest-value hour you can spend on this. I switched it on expecting to learn something academic and immediately found an N+1 in a page we'd shipped eight months earlier.