#11295 closed Cleanup/optimization (fixed)
If ModelAdmin.queryset returns a filtered QS don't require a 2nd count call
Reported by: | Alex Gaynor | Owned by: | Wiktor |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There is an optimization that tests QuerySet.query.where to see if we can reuse a count call, however we don't apply this optimization aggressively enough.
Attachments (2)
Change History (12)
by , 16 years ago
Attachment: | admin-count.diff added |
---|
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 15 years ago
Attachment: | admin-count.2.diff added |
---|
comment:2 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:3 by , 14 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
comment:5 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 12 years ago
I've updated patch so it applies correctly on current master.
Also, test in original patch assumes that there are 6 queries to db (including messages framework).
Currently, before applying patch there are 5 of them (including duplicated COUNT(*):
(Pdb) pprint(connection.queries) [{'sql': 'QUERY = \'SELECT "django_session"."session_key", "django_session"."session_data", "django_session"."expire_date" FROM "django_session" WHERE ("django_session"."session_key" = %s AND "django_session"."expire_date" > %s )\' - PARAMS = (\'2nj8364ycp90oge7xl5tf9mviz7grety\', \'2013-02-23 17:53:11.374277\')', 'time': '0.000'}, {'sql': 'QUERY = \'SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = %s \' - PARAMS = (100,)', 'time': '0.001'}, {'sql': 'QUERY = \'SELECT COUNT(*) FROM "admin_views_emptymodel" WHERE "admin_views_emptymodel"."id" > %s \' - PARAMS = (1,)', 'time': '0.000'}, {'sql': 'QUERY = \'SELECT COUNT(*) FROM "admin_views_emptymodel" WHERE "admin_views_emptymodel"."id" > %s \' - PARAMS = (1,)', 'time': '0.000'}, {'sql': 'QUERY = \'SELECT "admin_views_emptymodel"."id" FROM "admin_views_emptymodel" WHERE "admin_views_emptymodel"."id" > %s ORDER BY "admin_views_emptymodel"."id" DESC\' - PARAMS = (1,)', 'time': '0.000'}]
After patch was applied, COUNT(*) is executed once:
(Pdb) pprint(connection.queries) [{'sql': 'QUERY = \'SELECT "django_session"."session_key", "django_session"."session_data", "django_session"."expire_date" FROM "django_session" WHERE ("django_session"."session_key" = %s AND "django_session"."expire_date" > %s )\' - PARAMS = (\'5y65r95ng27kccdmkrtoo1qom7q4vhln\', \'2013-02-23 17:54:51.024189\')', 'time': '0.000'}, {'sql': 'QUERY = \'SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = %s \' - PARAMS = (100,)', 'time': '0.001'}, {'sql': 'QUERY = \'SELECT COUNT(*) FROM "admin_views_emptymodel" WHERE "admin_views_emptymodel"."id" > %s \' - PARAMS = (1,)', 'time': '0.000'}, {'sql': 'QUERY = \'SELECT "admin_views_emptymodel"."id" FROM "admin_views_emptymodel" WHERE "admin_views_emptymodel"."id" > %s ORDER BY "admin_views_emptymodel"."id" DESC\' - PARAMS = (1,)', 'time': '0.000'}]
comment:7 by , 12 years ago
comment:8 by , 12 years ago
Patch needs improvement: | unset |
---|
comment:9 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
admin-count.2.diff fails to apply cleanly on to trunk