Fix Error 500 viewing admin page due to statement timeouts
Uses PostgreSQL tuple estimates to provide a much faster yet approximate count. See https://wiki.postgresql.org/wiki/Slow_Counting and https://wiki.postgresql.org/wiki/Count_estimate for more details.
We only use this fast method if the table has been analyzed or vacuumed within the last hour.
On GitLab.com:
gitlabhq_production=# SELECT COUNT(*) FROM notes;
count
----------
59556763
(1 row)
Time: 14972.421 ms
gitlabhq_production=# SELECT reltuples::bigint AS estimate FROM pg_class where relname = 'notes';
estimate
----------
58840564
(1 row)
Time: 1.198 ms
The difference is 716,199, or 1.2%, but the timing difference is huge.
Closes #46255 (closed)
Edited by Stan Hu