-
Notifications
You must be signed in to change notification settings - Fork 21.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
explain
support for methods like last
, pluck
and count
`explain` can be called on a relation to explain how the database would execute a query. Currently `explain` doesn't work for queries using `last`, `pluck` or `count`, as these return the actual result instead of a relation. This makes it difficult to optimize these queries. By letting `explain` return a proxy instead, we can support these methods. ```ruby User.all.explain.count \# => "EXPLAIN SELECT COUNT(*) FROM `users`" User.all.explain.maximum(:id) \# => "EXPLAIN SELECT MAX(`users`.`id`) FROM `users`" ``` This breaks the existing behaviour in that it requires calling inspect after explain. ```ruby User.all.explain.inspect \# => "EXPLAIN SELECT `users`.* FROM `users`" ``` However, as `explain` is mostly used from the commandline, this won't be a problem as inspect is called automatically in IRB. Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
- Loading branch information
1 parent
f6f6b05
commit 1f83af3
Showing
8 changed files
with
188 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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