{"repo":"fatkodima/fast_count","free":true,"listed":false,"github":"https://github.com/fatkodima/fast_count","clone":"git clone https://github.com/fatkodima/fast_count.git","description":"Quickly get a count estimation for large tables (>99% of accuracy for PostgreSQL).","language":"Ruby","stars":275,"topics":["gem","mysql","postgresql","rails","ruby","performance"],"license":"MIT","category":"databases-storage","readme_excerpt":"FastCount Unfortunately, it's currently notoriously difficult and expensive to get an exact count on large tables. Luckily, there are some tricks for quickly getting fairly accurate estimates. For example, on a PostgreSQL table with over 450 million records, you can get a 99.82% accurate count within a fraction of the time. See the table below for an example dataset. SQL Result Accuracy Time --- --- --- --- SELECT count( ) FROM small table 2037104 100.000% 4.900s SELECT fast count('small table') 2036407 99.965% 0.050s SELECT count( ) FROM medium table 81716243 100.000% 257.5s SELECT fast count('medium table') 81600513 99.858% 0.048s SELECT count( ) FROM large table 455270802 100.000% 310.6s SELECT fast count('large table') 454448393 99.819% 0.046s These metrics were pulled from real PostgreSQL databases being used in a production environment. For MySQL, this gem uses internal statistics to return the estimated table's size. And as per documentation, it may vary from the actual value by as much as 40% to 50%. But still is useful to get a rough idea of the number of rows in very large tables (where COUNT( ) can literally take hours). Supports PostgreSQL, MySQL, MariaDB, and SQLite. Requirements - Ruby 3.2+ - ActiveRecord 7.1+ If you need support for older versions, open an issue. Installation Add this line to your application's Gemfile: And then execute: Or install it yourself as: If you are using PostgreSQL, you need to create a database function, used internally: with the con","default_branch":null,"files":null,"tree":[],"storefront":"/r/fatkodima","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/fatkodima/fast_count/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}