In an attempt to understand what PostgreSQL is doing I''ve just
concocted
a mixin that logs the result of EXPLAIN ANALYZE for the query just
executed. Now I only need to learn how to interpret the output...
module PostgreSQLExplain
def install
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
include BoilerPlate::Tools::PostgreSQLExplain::InstanceMethods
end
end
module_function :install
module InstanceMethods
protected
def log(sql, name)
result = super(sql, name)
if @logger && @logger.level <= Logger::DEBUG
explanation = @connection.exec(''EXPLAIN ANALYZE '' +
sql)
@logger.debug(
"start EXPLAIN ANALYZE\n" +
explanation.result.join("\n") +
"\nend EXPLAIN ANALYZE")
end
result
end
end
end
I enable this mixin with a snippet in environment.rb:
if RAILS_ENV == ''development''
require ''postgresql_explain''
PostgreSQLExplain.install
end
Michael
--
Michael Schuerig Most people would rather die than think.
mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org
In fact, they do.
http://www.schuerig.de/michael/ --Bertrand Russell