|
|
|
|
|
by cbm-vic-20
262 days ago
|
|
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 |
|