26.4 Changing Database Behavior Internally
We’ve focused entirely on limiting the number of queries we make, but sometimes the problem is how long a query takes to run.
Databases rely on indexing to speed queries up. In Chapter 3, we saw in passing that Django automatically indexes database columns that it expects to access often. Primary key and SlugField
columns are indexed so that any time we ask for a value from those columns the database returns a value as quickly as possible.
In some instances, this isn’t good enough. When finding a Post
object, Django isn’t asking the database to search for just a particular slug
but is instead asking for a particular slug in association with a year and month. The unique identifier for the Post
object ...
Get Django Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.