There's a common access pattern with object-relational mapping frameworks where an initial query will be used to get a list of ids, then an individual queries are emitted for each item to get the details of the items. For example, if you have a database table full of stories, and you want to see only the stories written by a certain author, it is common for a framework to have a function like
stories = get_stories(query)
which results in a SQL query like
SELECT id FROM stories WHERE author = ?
with the '?' being bound to some concrete value like "Jim".
Then, the framework will be used to do something like this
for id in stories {
story = get_story_by_id(id)
// do something with story
}
which results in N SQL queries with
SELECT title, author, date, content FROM stories WHERE id = ?
and there's your N+1
ComputerGuru
This plagues (plagued?) pretty much everything to do with WordPress, from core to every theme and plugin developed.
metadat
Oh yeah, the ORM thing (common side-effect with DB query abstractions) - I must not have been fully awake. Cheers and thank you for humoring me, @cbm-vic-20!
tehlike
With orms, it can be easy, but also often fixed with eager fetching too.
Then, the framework will be used to do something like this
which results in N SQL queries with and there's your N+1