Is there a way Django's {{{count()}}} can be optimised for such querysets?
This becomes especially useful for
[https://docs.djangoproject.com/en/4.1/ref/paginator/ Paginators] where
{{{count()}}} is used
[https://github.com/django/django/blob/4.1.3/django/core/paginator.py#L78
internally], and such querysets with large number of rows containing
foreign key field lookups won't slowdown pagination due to the unnecessary
joins.
--
Ticket URL: <https://code.djangoproject.com/ticket/34158>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
> Is there a way Django's {{{count()}}} can be optimised for such
querysets?
Not really. Moreover, this is a support question and Trac is not a support
channel. Closing per TicketClosingReasons/UseSupportChannels.
> This becomes especially useful for
[https://docs.djangoproject.com/en/4.1/ref/paginator/ Paginators] where
{{{count()}}} is used
[https://github.com/django/django/blob/4.1.3/django/core/paginator.py#L78
internally], and such querysets with large number of rows containing
foreign key field lookups won't slowdown pagination due to the unnecessary
joins.
See #23771 for some ideas on how to optimize the `Paginator` case.
--
Ticket URL: <https://code.djangoproject.com/ticket/34158#comment:1>