QuickCount

Active

Near-exact row counts for very large tables, in milliseconds instead of minutes.

SELECT COUNT(*) on a table with hundreds of millions of rows is a full scan. The database planner already knows roughly how many rows there are.

QuickCount adds Model.quick_count, which reads the planner’s row estimate and falls back to an exact count when the estimate is under a threshold (500,000 by default), so small tables stay exact and huge ones stay fast.

In the production numbers the README reports, a 455-million-row table counts in 0.046 seconds at 99.8% accuracy, against 310 seconds for an exact count. It supports PostgreSQL, including active_record-mti hierarchies, and MySQL, and can estimate arbitrary relations with count_estimate.

Highlights

  • 455M rows: 0.046 s estimated vs 310 s exact
  • Exact below a configurable threshold
  • count_estimate for filtered relations
  • PostgreSQL and MySQL

In practice

User.quick_count
User.quick_count(threshold: 1_000_000)
User.where(active: true).count_estimate

Looking for our apps?

upuppy and the rest of our commercial software, with support and contact, live at twilightcoders.com.