Blog52K views3,198 votes0 replies1,460 following
Django's N+1 Problem: Choosing Between select_related and prefetch_related
Django's lazy ORM makes N+1 queries easy to create. Learn when select_related's JOIN beats prefetch_related's second query, with a worked example and a test to lock in the fix.