Method: ActiveRecord::Relation#explain
- Defined in:
- activerecord/lib/active_record/relation.rb
#explain(*options) ⇒ Object
Runs EXPLAIN on the query or queries triggered by this relation and returns the result as a string. The string is formatted imitating the ones printed by the database shell.
User.all.explain
# EXPLAIN SELECT `users`.* FROM `users`
# ...
Note that this method actually runs the queries, since the results of some are needed by the next ones when eager loading is going on.
To run EXPLAIN on queries created by first, pluck and count, call these methods on explain:
User.all.explain.count
# EXPLAIN SELECT COUNT(*) FROM `users`
# ...
The column name can be passed if required:
User.all.explain.maximum(:id)
# EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
# ...
Please see further details in the Active Record Query Interface guide.
332 333 334 |
# File 'activerecord/lib/active_record/relation.rb', line 332 def explain(*) ExplainProxy.new(self, ) end |