FastPage applies the MySQL "deferred join" optimization to speed up your ActiveRecord offset/limit queries.
FastPage alternatives and similar gems
Based on the "Database Tools" category.
Alternatively, view fast_page alternatives based on common mentions on social networks and blogs.
PgHero9.4 2.1 L4 FastPage VS PgHeroA performance dashboard for Postgres
Blazer8.8 3.4 FastPage VS BlazerBusiness intelligence made simple
Database Cleaner8.5 0.0 L5 FastPage VS Database CleanerStrategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing.
Scenic8.4 7.0 L5 FastPage VS ScenicVersioned database views for Rails
Large Hadron Migrator7.8 0.0 L5 FastPage VS Large Hadron MigratorOnline MySQL schema migrations
Seed dump7.0 0.0 L5 FastPage VS Seed dumpRails 4/5 task to dump your data to db/seeds.rb
Rails DB6.7 0.0 L5 FastPage VS Rails DBRails Database Viewer and SQL Query Runner
Lol DBA6.6 0.0 L5 FastPage VS Lol DBAlol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
Foreigner6.5 0.0 L5 FastPage VS ForeignerAdds foreign key helpers to migrations and correctly dumps foreign keys to schema.rb
Squasher6.4 0.0 FastPage VS SquasherSquasher - squash your old migrations in a single command
Seed Fu6.4 0.0 L5 FastPage VS Seed FuAdvanced seed data handling for Rails, combining the best practices of several methods together.
Active Record Doctor6.3 5.1 FastPage VS Active Record DoctorIdentify database issues before they hit production.
Seedbank6.2 0.0 L5 FastPage VS SeedbankSeedbank gives your seed data a little structure. Create seeds for each environment, share seeds between environments and specify dependencies to load your seeds in order. All nicely integrated with simple rake tasks.
BatchLoader5.7 0.0 FastPage VS BatchLoader:zap: Powerful tool for avoiding N+1 DB or HTTP queries
Polo5.3 0.0 L5 FastPage VS PoloPolo travels through your database and creates sample snapshots so you can work with real world data in development.
SchemaPlus5.3 0.0 L4 FastPage VS SchemaPlusSchemaPlus provides a collection of enhancements and extensions to ActiveRecord
DatabaseConsistency5.2 0.0 FastPage VS DatabaseConsistencyThe tool to avoid various issues due to inconsistencies and inefficiencies between a database schema and application models.
DatabaseValidations5.1 0.0 FastPage VS DatabaseValidationsDatabase validations for ActiveRecord
Upsert5.1 0.0 L5 FastPage VS UpsertUpsert on MySQL, PostgreSQL, and SQLite3. Transparently creates functions (UDF) for MySQL and PostgreSQL; on SQLite3, uses INSERT OR IGNORE.
SecondBase4.2 0.0 L5 FastPage VS SecondBaseSeamless second database integration for Rails.
OnlineMigrations3.9 4.6 FastPage VS OnlineMigrationsCatch unsafe PostgreSQL migrations in development and run them easier in production (code helpers for table/column renaming, changing column type, adding columns with default, background migrations, etc).
QueryTrack3.2 4.4 FastPage VS QueryTrackFind time-consuming database queries for ActiveRecord-based Rails Apps
Shiba3.0 0.0 FastPage VS ShibaCatch bad SQL queries before they cause problems in production
Redis Dashboard2.5 0.0 FastPage VS Redis DashboardSinatra app to monitor Redis servers.
Ruby PG Extras2.2 0.0 FastPage VS Ruby PG ExtrasRuby PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more.
Ruby Whatsapp SDK2.1 7.8 FastPage VS Ruby Whatsapp SDKEmpower your communication with Whatsapp using our Ruby-based Cloud API and SDK. With our easy-to-use Whatsapp API, you can quickly create custom bots and streamline messaging. Get started today and see the difference in your communication process.
Nullalign1.5 0.0 FastPage VS NullalignFinds missing non-null constraints
PgDriveBackup1.2 0.0 FastPage VS PgDriveBackupSimple solution to make encrypted with ccrypt PostgreSQL backups and storing on Google Drive API
Slack Smart Bot1.1 10.0 FastPage VS Slack Smart BotCreate a Slack bot that is smart and so easy to expand, create new bots on demand, run ruby code on chat, create shortcuts... The main scope of this gem is to be used internally in the company so teams can create team channels with their own bot to help them on their daily work, almost everything is suitable to be automated!! slack-smart-bot can create bots on demand, create shortcuts, run ruby code... just on a chat channel. You can access it just from your mobile phone if you want and run those tests you forgot to run, get the results, restart a server... no limits.
ActiveRecord Setops1.0 0.0 FastPage VS ActiveRecord SetopsUnion, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
Perfect Shape1.0 0.0 FastPage VS Perfect ShapePerfect Shape is a collection of geometric algorithms that are mostly useful for GUI manipulation like checking containment of a point in popular geometric shapes such as rectangle, square, arc, circle, polygon, and paths containing lines, quadratic bézier curves, and cubic bezier curves. Also, some general math algorithms like IEEE-754 Remainder.
PgDice0.8 0.0 FastPage VS PgDicePostgres partitioning built on top of https://github.com/ankane/pgslice
ActiveRecord::DataIntegrityCheck data integrity for your ActiveRecord models
SlackHook0.5 0.0 FastPage VS SlackHookA Simple Interface to Slack Incoming Webhooks Integrations
ocran0.4 10.0 FastPage VS ocranOne-Click Ruby Application Builder
bundler-download0.4 0.0 FastPage VS bundler-downloadBundler plugin for auto-downloading specified extra files after gem install
TestGPT | Generating meaningful tests for busy devs
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of FastPage or a related project?
FastPage applies the MySQL "deferred join" optimization to your ActiveRecord offset/limit queries.⚡️
fast_page to your Gemfile.
You can then use the
fast_page method on any ActiveRecord::Relation that is using offset/limit.
Here is a slow pagination query:
Post.all.order(created_at: :desc).limit(25).offset(100) # Post Load (1228.7ms) SELECT `posts`.* FROM `posts` ORDER BY `posts`.`created_at` DESC LIMIT 25 OFFSET 100
.fast_page to your slow pagination query. It breaks it up into two, much faster queries.
Post.all.order(created_at: :desc).limit(25).offset(100).fast_page # Post Pluck (456.9ms) SELECT `posts`.`id` FROM `posts` ORDER BY `posts`.`created_at` DESC LIMIT 25 OFFSET 100 # Post Load (0.4ms) SELECT `posts`.* FROM `posts` WHERE `posts`.`id` IN (1271528, 1271527, 1271526, 1271525, 1271524, 1271523, 1271522, 1271521, 1271520, 1271519, 1271518, 1271517, 1271516, 1271515, 1271514, 1271512, 1271513, 1271511, 1271510, 1271509, 1271508, 1271507, 1271506, 1271505, 1271504) ORDER BY `posts`.`created_at` DESC
We wanted to see just how much faster using the deferred join could be. We took a table with about ~1 million records in it and benchmarked the standard ActiveRecord offset/limit query vs the query with FastPage.
Here is the query:
AuditLogEvent.page(num).per(100).where(owner: org).order(created_at: :desc)
created_at are indexed.
As you can see in the chart above, it's significantly faster the further into the table we paginate.
Compatible pagination libraries
FastPage has been tested and works with these existing popular pagination gems. If you try it with any other gems, please let us know!
.fast_page to the end of your existing Kaminari pagination queries.
In any controller that you want to use
fast_page, add the following method. This will modify the query Pagy uses when retrieving the records.
def pagy_get_items(collection, pagy) collection.offset(pagy.offset).limit(pagy.items).fast_page end
How this works
The most common form of pagination is implemented using LIMIT and OFFSET.
In this example, each page returns 50 blog posts. For the first page, we grab the first 50 posts. On the 2nd page we grab 100 posts and throw away the first 50. As the
OFFSET increases, each additional page becomes more expensive for the database to serve.
-- Page 1 SELECT * FROM posts ORDER BY created_at DESC LIMIT 50; -- Page 2 SELECT * FROM posts ORDER BY created_at DESC LIMIT 50 OFFSET 50; -- Page 3 SELECT * FROM posts ORDER BY created_at DESC LIMIT 50 OFFSET 100;
This method of pagination works well until you have a large number of records. The later pages become very expensive to serve. Because of this, applications will often have to limit the maximum number of pages they allow users to view or swap to cursor based pagination.
Deferred join technique
High Performance MySQL recommends using a "deferred join" to increase the efficiency of LIMIT/OFFSET pagination for large tables.
SELECT * FROM posts INNER JOIN(select id from posts ORDER BY created_at DESC LIMIT 50 OFFSET 10000) AS lim USING(id);
Notice that we first select the ID of all the rows we want to show, then the data for those rows. This technique works "because it lets the server examine as little data as possible in an index without accessing rows."
The FastPage gem makes it easy to apply this optimization to any
ActiveRecord::Relation using offset/limit.
To learn more on how this works, check out this blog post: Efficient Pagination Using Deferred Joins
When should I use this?
fast_page works best on pagination queries that include an
ORDER BY. It becomes more effective as the page number increases. You should test it on your application's data to see how it improves your query times.
We have only tested
fast_page with MySQL. It likely does not produce the same results for other databases. If you test it, please let us know!
fast_page runs 2 queries instead of 1, it is very likely a bit slower for early pages. The benefits begin as the user gets into deeper pages. It's worth testing to see at which page your application gets faster from using
fast_page and only applying to your queries then.
posts = Post.all.page(params[:page]).per(25) # Use fast page after page 5, improves query performance posts = posts.fast_page if params[:page] > 5
Thank you :heart:
This gem was inspired by Hammerstone's
fast-paginate for Laravel and @aarondfrancis's excellent blog post: Efficient Pagination Using Deferred Joins. We were so impressed with the results, we had to bring this to Rails as well.
Bug reports and pull requests are welcome on GitHub at https://github.com/planetscale/fast_page. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the Apache-2.0 license.
Code of Conduct
Everyone interacting in the FastPage project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
*Note that all licence references and agreements mentioned in the FastPage README section above are relevant to that project's source code only.