Opened 2 months ago

Closed 2 months ago

Last modified 2 months ago

#36497 closed New feature (duplicate)

Add ModelAdmin.estimated_count for faster changelist pagination

Reported by: rylaix Owned by: rylaix
Component: contrib.admin Version: 5.2
Severity: Normal Keywords: performance pagination
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (3)

comment:1 by Antoliny, 2 months ago

Has patch: set
Owner: set to rylaix
Status: newassigned

comment:2 by David Smith, 2 months ago

Resolution: duplicate
Status: assignedclosed

Duplicate of #8408

in reply to:  2 comment:3 by rylaix, 2 months ago

Replying to David Smith:

Duplicate of #8408

It is not a duplicate, but fair enough. Worth to combine them. Discussion moved to #8408

Note: See TracTickets for help on using tickets.
Back to Top