Opened 8 years ago

Last modified 6 years ago

#26964 closed Bug

No mention of index_together on the GenericForeignKey section — at Version 3

Reported by: Aidan Lister Owned by: nobody
Component: Documentation Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Aidan Lister)

We've been troubleshooting a performance issue and noticed that there was no index on an important GenericForiegnKey.

Once we'd resolved that, we noticed a contrib app had no index either (django reversion).

It seems like this should be mentioned in the documentation here:

https://docs.djangoproject.com/en/1.9/ref/contrib/contenttypes/#generic-relations

Suggested wording:

If you plan to search for child objects which have a generic relation to your parent object, e.g. find all tags linked to a piece of content, then you should consider adding a database index on the content type and object ID using index_together (https://docs.djangoproject.com/en/1.9/ref/models/options/#index-together). Django does not do this for you automatically as it does with ForeignKey's.

In the example above, this would look like:

    class Meta:
        index_together = [
            ["content_type", "object_id"],
        ]

Change History (3)

comment:1 by Aidan Lister, 8 years ago

Description: modified (diff)

comment:2 by Aidan Lister, 8 years ago

Description: modified (diff)

comment:3 by Aidan Lister, 8 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top