N Plus One Query (ARCH2050)
Esta página aún no está disponible en tu idioma.
Key python.orm.n-plus-one-query · Severity warning · Category orm
Opening a new query for related data on every loop iteration produces N+1 round-trips for N rows. It is the single biggest ORM performance killer.
Incorrect
Section titled “Incorrect”authors = Author.objects.all()for author in authors: print(author.profile.bio) # a separate SELECT per iterationCorrect
Section titled “Correct”authors = Author.objects.select_related("profile")for author in authors: print(author.profile.bio) # loaded in one JOINEager-load related data with select_related / prefetch_related instead of querying inside the loop.