PyCon Pittsburgh. April 15-23, 2020.

Talk: Big O No: Django ORM runtime complexity and how to avoid it using LATERAL JOINS

Presented by:

Chris Seto


N+1 queries are as common as blog posts about how to solve them. What happens when you want to get a list of blog posts, the comments on them, and the comments’ respective authors? An exponential number of queries. The rise of GraphQL and REST APIs that provide “include” semantics make these situations increasingly common and painful. Clever use of prefetch_related and select_related may help in a pinch but never fully solve the problem. Learn how to identify these inefficient queries and optimize them using SQL aggregations and LATERAL JOINs.


Watch on YouTube