Programming Tips - Postgresql: make count faster

Date: 2011jul26 Product: Postgresql Language: sql Q. Postgresql: make count faster
SELECT COUNT(*) FROM tablename;
is slow in Postgresql. How can I make it faster? A. Instead do:
SELECT reltuples FROM pg_class WHERE oid = 'schemaname.tablename'::regclass::oid;
The number returned is an estimate of the number of tables in the table at the time of the last ANALYZE. Source http://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT#COUNT.28.2A.29