Research indexBook chapter
Advanced Query Optimization
Surbier
Apress eBooks1 Jan 2026
NobleIDark:/48914/w1/20261105/E770513DDOI10.1007/979-8-8688-2900-0_14
Book chapter
Advanced Query Optimization
Surbier · Apress eBooks · 2026 · Subscription
NobleIDark:/48914/w1/20261105/E770513DDOI10.1007/979-8-8688-2900-0_14
PaywalledRead at the publisher
The full text is at the publisher
You can read the abstract here, or open it at the publisher.
Abstract
We learned to use select_related and prefetch_related to optimize our queries and how it’s important to do it to keep optimal performances. However, while Django’s ORM is powerful, sometimes raw SQL is necessary for complex optimizations. It may also be necessary to use raw SQL when Django’s ORM is not able to generate the query we need (or we don’t succeed to do what we want).