CREATE INDEX CONCURRENTLY!
ON auth_user (is_active)!
WHERE is_active = false;
Create an Index on is_active attribute
Slide 36
Slide 36 text
QUERY PLAN!
-------------------------------
Index Scan using
auth_user_is_active_idx on
auth_user!
!
(cost=0.00..59.19 rows=2413 width=140)!
(actual time=0.129..8.824 rows=2384 loops=1)!
!
Index Cond: (is_active = false)!
!
Total runtime: 9.779 ms!
!
(3 rows)
Slide 37
Slide 37 text
No content
Slide 38
Slide 38 text
Wait, how do I view
the SQL queries?
Slide 39
Slide 39 text
Django debug toolbar
Slide 40
Slide 40 text
Silk
Slide 41
Slide 41 text
Django Query Inspector
[SQL] repeated query (6x): SELECT "customer_role"."id",
"customer_role"."contact_id", "customer_role"."name"
FROM "customer_role" WHERE "customer_role"."contact_id" = ?
Suitable for API projects with no web UI
Slide 42
Slide 42 text
Search Engine?
PostgreSQL comes with full-text search
Heavy search traffic?
Consider Elasticsearch, Solr
Slide 43
Slide 43 text
No content
Slide 44
Slide 44 text
Haystack
Supports Elasticsearch, Solr and more
Easy to get started with manage.py commands
Familiar ORM syntax for searching
Slide 45
Slide 45 text
Doing a search
SearchQuerySet().models(Post).!
filter(content=‘Python’).all()!
!
[!
,!
,!
…]
Slide 46
Slide 46 text
Happy ORM
Use select/prefetch related to reduce queries
Understand your DB’s query planner
Haystack for search