To expand, a better answer is when you have profiled your application and have 
shown a bottleneck, and have tested it with an index on that column and seen an 
improvement. 

db_index isn't free, it incurs a penalty on writes so you need to be careful 
when using them. 


On Friday, September 16, 2011 at 12:08 AM, Micah Carrick wrote:

> As an oversimplification.. any time you will be looking up a record based on 
> a field, then you want an index on that (or those) fields. If you're finding 
> a row based on a slug, you want to index that slug field. 
> 
> A good tool is to use the Django debug toolbar. When you load a page you can 
> take a look at the SQL queries. You can then use the 'dbshell' management 
> command to open up your database shell. Then you can then add "EXPLAIN " 
> before the SELECT queries to see how it's finding your data. Do a google 
> search on your database indexes and you'll find all sorts of details. 
> On Thu, Sep 15, 2011 at 8:38 PM, Micky Hulse <rgmi...@gmail.com 
> (mailto:rgmi...@gmail.com)> wrote:
> >  Hello,
> > 
> >  I have been using this great category/tag model:
> > 
> > https://github.com/praekelt/django-category/blob/master/category/models.py
> > 
> >  ... and I noticed that the author added a db_index on the SlugField of
> >  the Category model.
> > 
> >  I hate to admit it, but I don't think I have ever explicitly used
> >  db_index parameter on any of my models.
> > 
> >  When's a good time to use db_index? Is there a general rule of thumb
> >  when coding Django models?
> > 
> >  Sorry if silly question.
> > 
> >  Thanks so much!
> > 
> >  Cheers,
> >  Micky
> > 
> >  --
> >  You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> >  To post to this group, send email to django-users@googlegroups.com 
> > (mailto:django-users@googlegroups.com).
> >  To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com 
> > (mailto:django-users%2bunsubscr...@googlegroups.com).
> >  For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en.
> > 
> 
>  -- 
>  You received this message because you are subscribed to the Google Groups 
> "Django users" group.
>  To post to this group, send email to django-users@googlegroups.com 
> (mailto:django-users@googlegroups.com).
>  To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> (mailto:django-users+unsubscr...@googlegroups.com).
>  For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to