Skip to content

Instantly share code, notes, and snippets.

@pawelztef
Created December 10, 2016 01:00
Show Gist options
  • Save pawelztef/3f2e541a666349da7f688762177f417a to your computer and use it in GitHub Desktop.
Save pawelztef/3f2e541a666349da7f688762177f417a to your computer and use it in GitHub Desktop.
Check missing indexes in Rails app
c = ActiveRecord::Base.connection
c.tables.collect do |t|
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{t}: #{unindexed.join(", ")}"
end
end
@pawelztef
Copy link
Author

run in rails console to check any missing indexes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment