This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Unnecessary indexes slows down writes and consumes additional storage and memory. | |
# Just paste this snippet in your Rails console (bundle exec rails c). | |
# And it will print all redundant indexes that are already covered by another index on the table: | |
# Table `pages`: index `site_idx` (site_id) already covered by `site_slug_idx` (site_id,slug) | |
# Table `optins`: index `list_idx` (list_id) already covered by `list_active_idx` (list_id,active) | |
ActiveRecord::Base.connection.tables.map do |table| | |
indexes = ActiveRecord::Base.connection.indexes(table).select(&:valid).reject(&:where) |