[Django] #36497: Add ModelAdmin.estimated_count for faster changelist pagination

14 views
Skip to first unread message

Django

unread,
Jul 7, 2025, 6:20:35 AM7/7/25
to django-...@googlegroups.com
#36497: Add ModelAdmin.estimated_count for faster changelist pagination
-------------------------------------+-------------------------------------
Reporter: rylaix | Type: New
| feature
Status: new | Component:
| contrib.admin
Version: 5.2 | Severity: Normal
Keywords: performance | Triage Stage:
pagination | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
This ticket proposes adding support for an `estimated_count = True` flag
on ModelAdmin to improve pagination performance on large datasets.

When enabled, the Django admin will use an estimated row count instead of
executing a full COUNT(*) in changelist views. This estimation is based
on:

- PostgreSQL: pg_class.reltuples
- MySQL: SHOW TABLE STATUS

The patch includes:

- `estimate_row_count()` helper function
- Support in `ChangeList.get_results()`
- Unit tests for fallback and estimation behavior
- Integration test for PostgreSQL
- Benchmark script
- Documentation of the new ModelAdmin.estimated_count attribute

If estimation fails or is unsupported, it gracefully falls back to the
standard `queryset.count()`.

A full patch is already available and a PR will be submitted shortly.
--
Ticket URL: <https://code.djangoproject.com/ticket/36497>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 7, 2025, 11:55:39 PM7/7/25
to django-...@googlegroups.com
#36497: Add ModelAdmin.estimated_count for faster changelist pagination
-------------------------------------+-------------------------------------
Reporter: rylaix | Owner: rylaix
Type: New feature | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: performance | Triage Stage:
pagination | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* has_patch: 0 => 1
* owner: (none) => rylaix
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36497#comment:1>

Django

unread,
Jul 8, 2025, 3:19:03 AM7/8/25
to django-...@googlegroups.com
#36497: Add ModelAdmin.estimated_count for faster changelist pagination
-------------------------------------+-------------------------------------
Reporter: rylaix | Owner: rylaix
Type: New feature | Status: closed
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution: duplicate
Keywords: performance | Triage Stage:
pagination | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Smith):

* resolution: => duplicate
* status: assigned => closed

Comment:

Duplicate of #8408
--
Ticket URL: <https://code.djangoproject.com/ticket/36497#comment:2>

Django

unread,
Jul 8, 2025, 5:40:28 AM7/8/25
to django-...@googlegroups.com
#36497: Add ModelAdmin.estimated_count for faster changelist pagination
-------------------------------------+-------------------------------------
Reporter: rylaix | Owner: rylaix
Type: New feature | Status: closed
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution: duplicate
Keywords: performance | Triage Stage:
pagination | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by rylaix):

Replying to [comment:2 David Smith]:
> Duplicate of #8408
It is not a duplicate, but fair enough. Worth to combine them. Discussion
moved to #8408
--
Ticket URL: <https://code.djangoproject.com/ticket/36497#comment:3>
Reply all
Reply to author
Forward
0 new messages