Django ORM: the N+1 problem

medium

`book.author.name` looks like a free attribute access and is a database round trip. Every query appears as it fires, so the count visibly tracks the row count - then switching strategy flattens it. Includes the case where only() reintroduces the bug.

Best O(1) queriesWorst O(n) queriesSpace O(n) rows
Loading django orm: the n+1 problem

Read the questions this explains