Making smarter queries with advanced ORM resources
summary
Builds a toy Django project, imports hundreds of thousands of rows with bulk_create, and shows concrete ORM patterns that actually improve runtime. Uses Prefetch(queryset=...) to load only expenses for a given month/year and cut extra rows, uses filtered aggregates like Sum('value', filter=Q(month=..., year=...)) and compares that to filtered relations, finding the filtered-aggregate SQL runs about ten times faster in the example. Demonstrates subqueries with OuterRef('name') to match companies by partner name and state.
AI-written summary · about
chapters (7)
- 0:00Introduction
- 2:00Why I came
- 8:10Whats the data
- 10:20Datasets
- 12:37Queries
- 19:24Aggregates
- 25:20Subqueries
related talks
25mBuilding effective Django queries with expressions
26mA Related Matter: Optimizing your webapp
30mBeyond faceted search
16mBig O No: Django ORM runtime complexity and how to avoid it using LATERAL JOINS
49mPrefetching for Fun and Profit
21mCustom Model Managers and QuerySets: Graduating from Django Beginner to ORM Master
01h 04mInside the ORM
23mOptimizing your webapp by using django-debug-toolbar
