Created
December 6, 2011 06:35
-
-
Save sirupsen/1437066 to your computer and use it in GitHub Desktop.
.ircrb entry to run explain on a query.
This file contains hidden or 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
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