Introduction
Database query optimization helps your Rails app get data faster. It makes your app feel quicker and saves server work.
When your app loads pages slowly because it asks the database too many times.
When you want to show related data without extra waiting.
When you notice your app uses a lot of memory or CPU because of big database queries.
When you want to reduce the number of database calls to save resources.
When you want to avoid loading unnecessary data from the database.