RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Efficiently Getting Random Records in Rails Active Record (with a benchmarking example)

Many applications require the retrieval of random database records (for instance to highlight a random product in an online store). There are several ways to accomplish this task, but efficiency varies widely and becomes more pronounced as your database grows in size. This blog post demonstrates two common approaches when using Rails Active Record and MySQL, and benchmarks both (using the Ruby Benchmark module) to demonstrate their efficiency.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in