Databases · Middle · Question 14 of 75
Why can SELECT COUNT(*) FROM big_table be slow in PostgreSQL?
- 1
COUNT(*)is not supported on large tables - ✓Correct answer: Because of MVCC each transaction may see different rows, so PostgreSQL has to scan to count visible ones
- 3PostgreSQL counts every column of every row
Explanation
If an approximate number is enough, read the estimate from pg_class.reltuples, or keep a counter updated by the application or a trigger.