Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Created December 6, 2011 06:35
Show Gist options
  • Save sirupsen/1437066 to your computer and use it in GitHub Desktop.
Save sirupsen/1437066 to your computer and use it in GitHub Desktop.
.ircrb entry to run explain on a query.
if defined? ActiveRecord
def explain(query)
query = query.to_sql if query.is_a?(ActiveRecord::Relation)
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