id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 18729 Admin changelist view defaults to `DISTINCT`, unusable on reasonably sized databases Henrique C. Alves AlexMalek "The default behavior on the admin is not usable for reasonably sized tables (a couple thousand tuples is enough for >1s queries). Right now, it always includes a `DISTINCT` clause if you add a M2M field on `list_filter`, even if you're not applying any filters. Use of `DISTINCT` is known to be painfully slow, and even more so without a `WHERE` clause, because it forces SQL databases into a full table scan. The behavior is not easily overridden because the logic is scattered on a couple `ChangeList` methods (https://github.com/django/django/blob/master/django/contrib/admin/views/main.py#L299). The only solution right now is not including a M2M field on `list_filter` and limiting functionality. It would be better if that behavior could be overridden (a `use_distinct` parameter on `get_query_set`?) or, optimally, moving this logic somewhere else. Ticket #15819 already includes a patch for that." Bug closed contrib.admin dev Normal fixed admin sql distinct slow performance Accepted 1 0 0 0 0 0