Supercharging ActiveRecord with PostreSQL
summary
Rails 4 ActiveRecord actually supports PostgreSQL arrays, hstore and ranges so the database does filtering and constraints instead of Ruby code; a GIN index on arrays yields roughly 50× speed in the presenter’s benchmark of 100,000 notes with 100 tags each and 10,000 possible tags; hstore values come back as strings so numbers need casting; use rank() window + CTE to compute correct leaderboard ranks without loading all scores into memory.
AI-written summary · about
chapters (5)
- 0:00Start
- 0:29Supercharging ActiveRecord with PostgreSQL
- 1:51What We'll Explore: Arrays • PostgreSQL has built in support for arrays of any datatype That includes user-defined types as well • Can be multi-dimensional • Child arrays must have the same number of elements as their siblings
- 7:50Some Benchmarking • 100,000 notes, each with 100 tags • 10,000 possible tags • Table was cached by scanning it once • Run on a MacBook Pro Retina with 16GB of RAM and SSD • Noticeably slower reads on a Mac Mini with spinning metal
- 20:35Wrapping Up • PostgreSQL has some really powerful features baked in • Your situation ultimately dictates the best approach • Play with different solutions to see what is the best performance/maintainability trade off for your specific use case • Don't just use it because "It's new/cool"








