- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
? Your Django app is slow. Do this before reaching for Raw SQL:
Add indexes to WHERE-heavy fields
Use select_related() / prefetch_related()
Cache expensive queries with Redis
Let the DB do the math: annotate(), aggregate()
Send thousands of rows at once with bulk_create()
? When ORM hits the wall, Raw SQL wins at:
• Complex joins, window functions, geo-batching
• Mass updates & deletes (millions of rows)
• Vendor tricks: PostGIS, UNNEST, JSON_TABLE
• Fine-tuned EXPLAIN-based optimization
? Takeaway:
Use ORM for safety, clarity, and 90% of work.
Use Raw SQL for speed, control, or edge cases — but wrap in tests and sanitize inputs.
? Full breakdown here:
? When ORM hits the wall, Raw SQL wins at:
• Complex joins, window functions, geo-batching
• Mass updates & deletes (millions of rows)
• Vendor tricks: PostGIS, UNNEST, JSON_TABLE
• Fine-tuned EXPLAIN-based optimization
? Takeaway:
Use ORM for safety, clarity, and 90% of work.
Use Raw SQL for speed, control, or edge cases — but wrap in tests and sanitize inputs.
? Full breakdown here: