Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Great idea, but my estimate was off by a much too significant amount using this function - about 31000 rows total, with the estimate returning about 20000, despite recently running an ANALYZE on the table (and not persisting any rows in the meantime).
"If you have a secondary index on the PK field, it will be able to perform less IO to perform a count." Stop spreading unsubstantiated claims without backing them up. See this post, and this post. I've yet to find a single source backing up your claim.
Approaching it from a purely empirical perspective in Postgres, I noticed that when I (accidentally) created an index on the columns that were already my primary key (same columns, same order), Postgres actually gave a slightly higher cost without the extra index (through EXPLAIN). Of course, that is just one database, plus the cost difference was less than a percent.