Skip to content
A rake task to track down missing database indexes. does not assume that all foreign keys end with the convention of _id.
Branch: master
Clone or download
Pull request Compare This branch is 6 commits ahead, 7 commits behind eladmeidar:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
rails_indexes.gemspec

README.md

#Rails Indexes

Rails indexes is a small package of 2 rake tasks that scan your application models and displays a list of columns that probably should be indexed.

Note: there should be mode fields depending on your application design and custom queries.

Installation

Add rails_indexes to your Gemfile:

gem "rails_indexes", :git => "https://github.com/warpc/rails_indexes"

and install gem

bundle install

Usage

Display a migration for adding/removing all necessary indexes based on associations:

rake db:index_migration

Display a migration for adding/removing all necessary indexes based on AR::Base#find calls (including: find, find_by, find_all_by, find_by_x_and_y, find_all_by_x_and_y):

rake db:find_query_indexes

Notice: At now moment it does not support Arel(the new Rails 3 Active Record Query Interface) calls (including: where, joins, includes, from, select...), but still usefull for indexes based on association

Note that add index in big database may take a long time.

Compatibility

Compatible with Ruby 1.9 and Rails 3.

Upcoming features/enhancements

  • Support Arel(the new Rails 3 Active Record Query Interface) call for find_query_indexes action

Differences from the original rails_indexes

  • Compatible with Ruby 1.9 and Rails 3
  • Installing as Gem
  • Analize has_many :through associations
  • Working STI analize
  • Good test coverage with RSpec
  • Do not suggest add index for primary key (about reason read below)

About primary_key

The primary key is always indexed. This is generally true for all storage engines that at all supports indices.

For this reason, no longer displays a gem suggestions about adding indexes to primary keys.

Tests

bundle install
rake

to run the tests.

Feedback

All feedback, bug reports and thoughts on this gratefully received.

Author:

Elad Meidar - http://blog.eizesus.com

Thanks: Eric Davis - http://littlestreamsoftware.com

License

Released under the same license as Ruby. No Support. No Warranty, no Pain.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.