diff --git a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-after.png b/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-after.png deleted file mode 100644 index 6b64873b15608..0000000000000 Binary files a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-after.png and /dev/null differ diff --git a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-before.png b/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-before.png deleted file mode 100644 index 682a1ed1ee4cd..0000000000000 Binary files a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-before.png and /dev/null differ diff --git a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-detector-settings.png b/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-detector-settings.png index 3971000cb07d7..71bb135339976 100644 Binary files a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-detector-settings.png and b/docs/product/issues/issue-details/performance-issues/img/n-plus-one-queries-detector-settings.png differ diff --git a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-span-evidence.png b/docs/product/issues/issue-details/performance-issues/img/n-plus-one-span-evidence.png index 6428da4799cb5..de2378390d00e 100644 Binary files a/docs/product/issues/issue-details/performance-issues/img/n-plus-one-span-evidence.png and b/docs/product/issues/issue-details/performance-issues/img/n-plus-one-span-evidence.png differ diff --git a/docs/product/issues/issue-details/performance-issues/n-one-queries.mdx b/docs/product/issues/issue-details/performance-issues/n-one-queries.mdx index a1111d564fdc4..e5398b2bc9144 100644 --- a/docs/product/issues/issue-details/performance-issues/n-one-queries.mdx +++ b/docs/product/issues/issue-details/performance-issues/n-one-queries.mdx @@ -30,7 +30,9 @@ The evidence for an N+1 Queries problem has four main aspects: - Transaction name - Parent span - This can be a view, a serializer, or another span that logically groups the queries. +- Preceding span - The last span recorded before the N+1 query spans. - Repeating span - This is the "N" of N+1 queries. This is the looped query that should have been part of a bulk query. +- Waterfall trace view - Shows the relevant sequential, non-overlapping database spans. ![N+1 Query span evidence](./img/n-plus-one-span-evidence.png) @@ -51,9 +53,7 @@ def books(request): return HttpResponse((", ").join(book_list)) ``` -This code has a subtle performance problem. Each call to `book.author.name` makes a query to fetch the book's author. In total, this code makes 11 queries: one query to fetch the list of books, and 10 more queries to fetch the author of each book. This results in a characteristic query span waterfall: - -![N+1 queries in an example application](./img/n-plus-one-queries-before.png) +This code has a subtle performance problem. Each call to `book.author.name` makes a query to fetch the book's author. In total, this code makes 11 queries: one query to fetch the list of books, and 10 more queries to fetch the author of each book. This results in a characteristic query span waterfall. In order to fix this performance issue, you could use the `select_related` method in Django, like so: @@ -66,9 +66,7 @@ def books(request): return HttpResponse((", ").join(book_list)) ``` -Django will `JOIN` the tables ahead of time, and preload the author information. That way, calling `book.author.name` does not need to make an extra query. Instead of a long waterfall, there is a single `SELECT` query: - -![Solved N+1 queries in an example application](./img/n-plus-one-queries-after.png) +Django will `JOIN` the tables ahead of time, and preload the author information. That way, calling `book.author.name` does not need to make an extra query. Instead of a long span waterfall, there is a single `SELECT` query. N+1s can also happen when modifying data. For example, instead of creating objects in a loop: