2 ms·
I wouldn't say "SQL Programmers" (or more likely, programmers who do SQL) are "proud" of their large queries, but they are a fact of life in most businesses. Re
by mickeyp 15y ago
I wouldn't say "SQL Programmers" (or more likely, programmers who do SQL) are "proud" of their large queries, but they are a fact of life in most businesses. Report generation and other complex business logic does take up a lot of lines, and it is indeed "good form" to keep it in one query when it makes sense to do so, or farm out some of the work to views or even materialised views, depending on what you need. Once you're used to reading it you'll quickly realise that most queries are actually made up of many sub queries nested inside and that they are mostly independent of the larger, parent, query.
Having said that, ORMs are terrible at generating efficient queries for anything but toy requirements. Optimising a query is hard for a human and even harder for an ORM. That massive query could just as well have been a product of the ORM.
I'm sure developers out there get by with just an ORM and treat it like a Chinese wall between them and the mystery black box that is the RDBMS. I think that's a huge mistake. Relational DBs are incredibly powerful.