PostgreSQL - Count() Performance Boost
Counting is a slow measure in Postgresql, and it is even slower with a lot of data and complex statements. This issue is related with the kind of how the data consistency is implemented. As a result Postgresql must check the visiblity of all rows first and so it has to iterate over them all.