Optimize Database Performance in Rails and ActiveRecord (Rails 8.1)
To optimize database performance in Ruby on Rails, fix N+1 queries with includes, preload, or eager_load; index the columns your WHERE and JOIN clauses filter on; load only the columns you use with select and pluck; batch large reads and writes with find_each and insert_all; and move to read replicas or sharding only once query-level fixes run out.