On Mon, 2009-01-19 at 16:55 -0800, Andrew Fong wrote: > I'm using contrib.contenttypes and have added the following to my > model: > > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > content_object = generic.GenericForeignKey() > > When examining the DB (I'm using MySQL), I find that content_type is > indexed but object_id is not. I was going to just index object_id, but > it makes more sense to put a composite index on both content_type and > object_id together. Unfortunately, I have no idea how to do this > without writing raw SQL.
Right. So the solution is to use raw SQL. Django is not intended to be a complete replacement for interacting with the database via SQL. That's why connection.cursor() is exposed, for example. It's not entirely clear why we aren't using a multi-column index there, however, beyond the fact that it might just have been overlooked. I'll talk to Jacob about it at some point (since he wrote that stuff). If we did that, it should be in the order (content_type, object_id), since querying on object_id without content_type doesn't make sense, whereas the reverse possibly does (although will also be fairly uncommon). Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

