Skip to content

Instantly share code, notes, and snippets.

@joncode
Created August 7, 2014 00:06
Show Gist options
  • Select an option

  • Save joncode/4887c23a894731e79fff to your computer and use it in GitHub Desktop.

Select an option

Save joncode/4887c23a894731e79fff to your computer and use it in GitHub Desktop.
to see what foreign keys in your app havent been indexed
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
got this from https://tomafro.net/tags/indexes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment