#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.