django/django — pull request #113 by svartalf (2012-06-06 03:51:16+00:00)
Title: Database indexes for some of contrib.auth.models.User fields

It is not a very quick operation: iterate over users table with some joins within. For example, code like this will works slow, because it iterates over a whole `auth_user` table firstly (checked at MySQL):

permission = Permission.objects.get(…)
slow_query_is_here = User.objects.filter(Q(is_staff=True),
Q(user_permissions=permission) | Q(groups__permissions=permission)).distinct()

Database indexes for fields `is_staff`, `is_active` and `is_superuser` helps here.