7 ms·
It's a general database access anti-pattern. It happens when you make one simple query to get a list of stuff. Then for every row, you fire off another query to
by ufmace 3y ago
It's a general database access anti-pattern. It happens when you make one simple query to get a list of stuff. Then for every row, you fire off another query to get more details about that item. Instead of this, a single properly-designed query could have retrieved everything you need, and nothing you didn't. This can be highly detrimental to both application and database performance, especially if the number of initial results gets long or you have another layer of query loops after the first one.
ORMs are notorious for making it easy to write this anti-pattern without noticing, though you can do it in raw SQL too. ORMs usually also have various helpers for eager loading of associations to try and prevent it. In raw SQL, it's on you to notice that you're doing it and write the correct query.