PostgreSQL Count(*) Performance Improvements
Most people have no trouble understanding that the following is slow:
After all, it is a complicated query, and PostgreSQL has to calculate the result before it knows how many rows it will contain. To mitigate this problem, PostgreSQL has introduced the visibility map, a data structure that stores if all tuples in a table block are visible to everybody or not. I wrote above that PostgreSQL does not store the row count in the table.
Source: www.cybertec-postgresql.com