TLDR Web Dev · QUICK LINKS
UNDERSTANDING WHY COUNT(*) CAN BE SLOW IN POSTGRESQL
Summary from the TLDR Web Dev newsletter
COUNT(*) can be slow in PostgreSQL due to MVCC and the need to verify row visibility, but optimizations like filtering on indexed columns or using approximate counts from pg_class can speed the query up.