Methods
Instance Public methods
build_explain_clause(options = []) Link
# File activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb, line 37 def build_explain_clause(options = []) return "EXPLAIN" if options.empty? options = options.flat_map do |option| option.is_a?(Hash) ? option.to_a.map { |nested| nested.join("=") } : option end explain_clause = "EXPLAIN #{options.join(" ").upcase}" if analyze_without_explain? && explain_clause.include?("ANALYZE") explain_clause.sub("EXPLAIN ", "") else explain_clause end end
explain(arel_or_sql, binds = [], options = []) Link
# File activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb, line 27 def explain(arel_or_sql, binds = [], options = []) sql, binds = to_sql_and_binds(arel_or_sql, binds) sql = build_explain_clause(options) + " " + sql start = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = select_all(sql, "EXPLAIN", binds) elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start MySQL::ExplainPrettyPrinter.new.pp(result, elapsed) end