3 ms·
I think ORMs are part of the problem. By abstracting away SQL, it becomes really easy to write something that generates terribly inefficient SQL without realizi
by nijave 5y ago
I think ORMs are part of the problem. By abstracting away SQL, it becomes really easy to write something that generates terribly inefficient SQL without realizing. It's easy to not realize it in small test environments with small test amounts of data, too.
Even a single n+1 query can really hose performance by burdening the entire database.
- gosukiwi 5y agoNowadays in Rails-land there's lots of tools to manage that, [the latest](https://blog.saeloun.com/2020/02/25/rails-strict-loading-mode-to-fix-n-1.html https://blog.saeloun.com/2020/02/25/rails-strict-loading-mod...) integrated into Rails itself. ORMs can be bad, but it's not fair to blame them "just because".
- whakim 5y agoI'm not so sure. My experience is that ORMs often discourage (or at least lessen the need for) getting a good grasp on databases and SQL because they abstract away a lot of fundamentals. Like any abstraction, there are obviously benefits too, but I do think it's reasonable to say that "makes it too easy to write sloppy/unperformant queries" is a real cost.
- gosukiwi 5y ago> My experience is that ORMs often discourage (or at least lessen the need for) getting a good grasp on databases and SQL I agree knowing SQL is very important, even if you use an ORM, sometimes you might need to roll up your sleeves and write some SQL (not to even mention knowing how to EXPLAIN queries, use indexes, etc). Nowadays most things are abstracted away. A similar thing happens with IDEs, if your IDE takes care of compiling and building everything for you, then you don't understand how everything works under the hood. Is that a bad thing? It depends. If you show HTML to a junior JS dev he'll say it's React, lol. I think there's no way escaping the abstractions in modern times.
- viraptor 5y agoThis is a popular trope, but in practice it's just as easy to do n+1 via your own abstractions where "items.each { |i| i.foo }" happens to do it too. Without any ORM involved. Everyone will do it sometimes and the question is only whether you're going to spot it before it causes an outage. (In many cases it will only cause a slight slowdown) At least there are tools to warn you about n+1 automatically https://github.com/flyerhzm/bullet https://github.com/flyerhzm/bullet