Date: 2011jul26
Product: Postgresql
Q.
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
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment