SQLite Forum

Approximate COUNT(*) using sqlite_stat4
There's [this thread](http://sqlite.1065341.n5.nabble.com/A-CTE-to-count-the-records-rows-for-each-table-td94615.html) which ends with a post from Richard stating that (at the time of writing, 2017) ANALYZE does an exact count, but he has some code on a branch that does an approximate count, which _might_ make it to trunk (no idea whether it did).

There's also an [older thread](http://sqlite.1065341.n5.nabble.com/Counting-rows-td79573.html) (2014) that talks about counting rows in large tables, and includes [this post from Richard](http://sqlite.1065341.n5.nabble.com/Counting-rows-tp79573p79604.html) that discusses a potential (but file-format-breaking) technique to do `count(*)` in logarithmic time by being able to store/compute a "rank" for entries in the b-tree table.