5 ms·
Yeah most N+1 issues can be mitigated by optimizing the queries. You definitely don't need an ORM to get to N+1 hell, a for-loop in vanilla PHP will do.
by pphysch 4y ago
Yeah most N+1 issues can be mitigated by optimizing the queries.
You definitely don't need an ORM to get to N+1 hell, a for-loop in vanilla PHP will do.
- mgkimsal 4y agoA for-loop in vanilla anything will do. Nothing special about PHP. Ruby, Python, Java, etc...
- pphysch 4y agoOf course. PHP is the one you will mainly encounter in the wilderness, though.
- 0x457 4y agoMost common place I saw N+1 is ActiveRecord (Ruby on Rails). Because by default, no relationships are loaded and the way AR "loads" stuff makes is extremely easy to create N+M queries on 5 lines of ruby. Then, those people will tell you that you run out of database before you run out of ruby...
- woooooo 4y agoYeah, but you have to go out of your way to do that. If you're in touch with the SQL you're executing at all, the join is the obvious easy way to do it, it's not some arcane optimization.
- RussianCow 4y agoThat’s a really big “if”. In my experience, most application engineers aren’t very good at SQL because they don’t have to be; most apps just don't ever reach a scale where it matters, and something like Rails or Django with N+1 queries all over the place performs just fine.
- woooooo 4y agoHence my 2 decade losing battle against ORM at every place I've worked :) I'm, like, 1 for 10 maybe.
- tyingq 4y agoYou do see it often in things like canned ecommerce software. They have this ecosystem that encourages you to add widgets to category listings, product listings, etc, that all create queries keying off the page context. Where widgets might be "similar items", "people that bought x, bought y", "recent purchases of this widget", "best sellers in this category" and so on.