Opened 2 years ago
Closed 2 years ago
#34158 closed Cleanup/optimization (invalid)
Optimise count() for querysets that contain field lookups
Reported by: | Irfan | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
These two lines are equivalent in terms of the count, yet one is much slower than the other.
Is there a way Django's count()
can be optimised for such querysets?
This becomes especially useful for Paginators where count()
is used internally, and such querysets with large number of rows containing foreign key field lookups won't slowdown pagination due to the unnecessary joins.
Note:
See TracTickets
for help on using tickets.
Not really. Moreover, this is a support question and Trac is not a support channel. Closing per TicketClosingReasons/UseSupportChannels.
See #23771 for some ideas on how to optimize the
Paginator
case.