Skip to content

Instantly share code, notes, and snippets.

@haileys
Forked from sirupsen/explain.rb
Created December 7, 2011 09:11
Show Gist options
  • Save haileys/1442099 to your computer and use it in GitHub Desktop.
Save haileys/1442099 to your computer and use it in GitHub Desktop.
if defined? ActiveRecord
def explain(query)
query = query.to_sql if query.respond_to? :to_sql
ActiveRecord::Base.connection
.execute("EXPLAIN ANALYZE #{query}")
.to_a
.each { |hash| puts hash["QUERY PLAN"] }
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment