ORM N+1 queries: a list page making one query per row
@devsingh05▲ 5 net votes
Rendering a list and accessing a relation per item (listing.owner.name) triggers one query per row, which is slow even with modest data. Load relations up front: select_related or prefetch_related in Django, selectinload or joinedload in SQLAlchemy, include in Prisma, with in Drizzle. Turn on SQL logging in development to see the query count per request.