#25230: Change to Query.get_count() causes big performance hit -------------------------------------+------------------------------------- Reporter: dexity | Owner: nobody Type: | Status: new Cleanup/optimization | Component: Database layer | Version: 1.8 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by jarshwah): akaariai's argument against fixing this makes sense to me. The distinct in `Model.objects.distinct().count()` is redundant, because the `pk` enforces that each row will be distinct anyway. For the cases where `distinct` will actually change the result, then a subquery is required. So even if we decide to fix this, I don't think it warrants release blocker status. Fix the queryset by removing the redundant `distinct`. If we can demonstrate that changing the queryset to be correct is non- obvious, then I think that might push the case for implementing a fix. Really though, distinct is very rarely useful, and is indicative of a poorly constructed query (in sql or in django). Obviously there are useful distinct queries, but they are the exception in my experience. -- Ticket URL: <https://code.djangoproject.com/ticket/25230#comment:7> 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/064.be2fa01674d494ebb82ff5a810a2909e%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.