#28477: Strip unused annotations from count queries -------------------------------------+------------------------------------- Reporter: Tom | Owner: nobody Type: | Status: new Cleanup/optimization | Component: Database | Version: master layer (models, ORM) | Severity: Normal | Keywords: Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- The query below produces a SQL statement that includes the Count('chapters'), despite not not being used in any filter operations.
{{{ Book.objects.annotate(Count('chapters')).count() }}} It produces the same results as: {{{ Book.objects.count() }}} Django could be more intelligent about what annotations to include in the query produced by `queryset.count()`, stripping out any annotations that are not referenced by filters, other annotations or ordering. This should speed up calls to count() with complex annotations. There seems to be precedent for this: select_related calls are ignored with count() queries. -- Ticket URL: <https://code.djangoproject.com/ticket/28477> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/046.c1837b66f4d69affc94b522dc946ace8%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.