~/talk

Thinking in SQL with Django

Talkat Django Day Copenhagen 2022 · on Friday, 2022-04-08· [django, databases]
slides:none on file

Profiling uses Django's Explain, queryset .query, django-debug-toolbar and django-extensions shell_plus --print-sql to spot an N+1 on pizzas and toppings; fix one adds prefetch_related and assertNumQueries tests to keep gains. Instead of Python loops, model toppings with numeric ratings and compute vegan/vegetarian via annotate + Case/When and a Subquery with OuterRef against the through table to force inner joins; result removes a costly hash aggregate, drops CPU load, and fixes responsiveness with a one-line change and no raw SQL.

AI-written summary · about

  1. 0:00Introduction and motivation
  2. 1:03Why SQL matters today
  3. 4:16Tools for profiling and debugging
  4. 5:41Pizza and toppings use case
  5. 8:11Fixing N+1 query problem
  6. 10:18Moving logic to the database
  7. 13:49Avoiding outer joins in SQL
  8. 18:44Optimizing with subqueries
  9. 20:13Key takeaways and lessons
  10. 22:44Q&A session
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.