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.
O(1) queriesWorst O(n) queriesSpace O(n) rowsRead the questions this explains
Django-21-25
Django - select_related vs prefetch_related, CSRF Protection, Security Best Practices, Auth vs Authorization, Password Hashing
Django-46-50
Django - Deployment (EC2, RDS, S3), JWT Auth, Debugging, N+1 Queries, Custom Middleware
DB-MySQL-11-15
Databases - Composite Index, Covering Index, EXPLAIN, Query Optimization