Missing indexes on database tables causes performance issues.
gem helps finding out missing indexes on database table in Rails code.
lol_dba performs static analysis of the code to find out missing indexes.
We will take a look at how to use
lol_dba to find out indexes.
lol_dba also helps creating a migration to add the requred indices.
The missing indexes suggested by
lol_dba is just a guideline.
It suggests which columns should probably be indexed.
It is not mandatory to add indices on the suggested tables.
lol_dba can be used just as a gem and not adding it to Gemfile.
You can add it to
Gemfile. This way, it will expose rake tasks.
Once gem is installed, we can find missing indexes using the following command:
This will output a migration with
for the database tables with column name.
Perform the migration
Figure out relevant indices for the application by looking at the suggested indices
Then, run the migrations to finetune performance of the Rails application.
Primary key is always indexed. It is not considered by
lol_dbawhile suggesting indices.
Generate SQLs from migrations:
- Generate SQLs from migrations with the help of rake task.
- Generate SQLs for only pending migrations.
- Generate SQLs for only for the migration with a version number
When fine tuning the performance with Ruby on Rails application,
lol_dba comes in handy to find out which database tables
This can be used as a guideline to add missing indexes
and improve performance of the application.
Subscribe to Ruby in Rails
Get the latest posts delivered right to your inbox