On Mar 23, 11:45 am, Javier Guerra Giraldez <[email protected]> wrote: > > >http://dpaste.com/524865/ > > ok, now it's obvious. > > the second query (the one with topic__forum__in=forums, right?) is > scanning the whole topic table (12Krows). it seems to be guessing > that picking a significant fraction of a very small space (5 forums > out of 15, right?) wouldn't be so much better using the index. > > the first query is using the topic->forum key, narrowing the loop to > the ~1388 topics of the given forum. > > now, how to improve this? it seems a little denormalization is in > order. i can thing of two different options: > > A: add a 'last_post_date' field to the topics table, and select only > the most recent 10 or so topics. > > B: add a new post->forum relation, and maybe a (forum,post_date) index >
Thank you very much for your insight Javiar. I've learned a lot here. I will try to denormalize. I might already have such a field in the topic model I could use. I have an "update_date" field in the topic model that I denormalized for display purposes; it is just the date of the last post in the topic. It isn't quite clear to me how to proceed yet, but you've given me some things to think about. So you are suggesting I need to shrink the number of topics or possibly link the posts directly to the forum? Thanks again, BN -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

