3 ms·
I appreciate approaches that acknowledge when “close” is good enough. It would be interesting to graph how far off those numbers are to put a real metric to it.
by brightball 8y ago
I appreciate approaches that acknowledge when “close” is good enough. It would be interesting to graph how far off those numbers are to put a real metric to it.
- davidgould 8y agoIf you are using a recent postgreql release and have just run ANALYZE, the pg_class.reltuples percentage error relative to the true row count will almost always be less than 1.0/DEFAULT_STATISTICS_TARGET, and usually substantially better than that.
- nieve 8y agoOnly one data point, but I've got a custom search engine for a community that has pretty close to the ideal usage pattern for this: append-only with no update or deletes. A pure count(*) over 6.8M rows on a slow VPS takes 135,015ms and the n_live_tup technique¹ takes 214ms. The latter was 00.009557% high before an analyze and 00.001414% low afterward. Definitely good enough for me. ¹ SELECT n_live_tup FROM pg_stat_all_tables WHERE relname = 'comments';