cannblw / knex-paginator

Simple paginator for Knex. It adds the .paginate() function to Knex's query builder.
15 stars 10 forks source link

faster / less precise query for counting total rows #11

Closed ArthurSango closed 5 years ago

ArthurSango commented 5 years ago

I have added a preciseCount argument, which defaults to true. If you need to get a count for a large table and don't require it to be exact, make preciseCount false. Based on this article: http://www.dbrnd.com/2015/10/postgresql-fast-way-to-find-the-row-count-of-a-table/ , it queries the pg_stat_user_tables to get an approximate count. This should help speed up queries on larger tables.

On some occasions, the approximate count is equal to the exact count, on others I have find it to be unfortunately quite inaccurate. Please bear in mind that I only have a few months experience with PSQL and Node, so my testing hasn't been extensive.

Thanks for the library!