Class: ActiveRecord::ConnectionAdapters::Mysql2Adapter::ExplainPrettyPrinter
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::Mysql2Adapter::ExplainPrettyPrinter
- Defined in:
- activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#pp(result, elapsed) ⇒ Object
Pretty prints the result of a EXPLAIN in a way that resembles the output of the MySQL shell:.
Instance Method Details
#pp(result, elapsed) ⇒ Object
Pretty prints the result of a EXPLAIN in a way that resembles the output of the MySQL shell:
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
| 1 | SIMPLE | posts | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
2 rows in set (0.00 sec)
This is an exercise in Ruby hyperrealism :).
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb', line 134 def pp(result, elapsed) widths = compute_column_widths(result) separator = build_separator(widths) pp = [] pp << separator pp << build_cells(result.columns, widths) pp << separator result.rows.each do |row| pp << build_cells(row, widths) end pp << separator pp << (result.rows.length, elapsed) pp.join("\n") + "\n" end |