Skip to content

Commit 2e2a3c3

Browse files
authored
Merge pull request rails#51506 from alonsogarciapablo/patch-1
[ci skip] Update "Running EXPLAIN" section in the "Active Record Query Interface" guide
2 parents dbb5c4a + 46a1d7f commit 2e2a3c3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

guides/source/active_record_querying.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,13 +2610,13 @@ Running EXPLAIN
26102610

26112611
You can run [`explain`][] on a relation. EXPLAIN output varies for each database.
26122612

2613-
For example, running
2613+
For example, running:
26142614

26152615
```ruby
26162616
Customer.where(id: 1).joins(:orders).explain
26172617
```
26182618

2619-
may yield
2619+
may yield this for MySQL and MariaDB:
26202620

26212621
```sql
26222622
EXPLAIN SELECT `customers`.* FROM `customers` INNER JOIN `orders` ON `orders`.`customer_id` = `customers`.`id` WHERE `customers`.`id` = 1
@@ -2636,11 +2636,9 @@ EXPLAIN SELECT `customers`.* FROM `customers` INNER JOIN `orders` ON `orders`.`c
26362636
2 rows in set (0.00 sec)
26372637
```
26382638

2639-
under MySQL and MariaDB.
2640-
26412639
Active Record performs a pretty printing that emulates that of the
26422640
corresponding database shell. So, the same query running with the
2643-
PostgreSQL adapter would yield instead
2641+
PostgreSQL adapter would yield instead:
26442642

26452643
```sql
26462644
EXPLAIN SELECT "customers".* FROM "customers" INNER JOIN "orders" ON "orders"."customer_id" = "customers"."id" WHERE "customers"."id" = $1 [["id", 1]]
@@ -2658,7 +2656,7 @@ EXPLAIN SELECT "customers".* FROM "customers" INNER JOIN "orders" ON "orders"."c
26582656

26592657
Eager loading may trigger more than one query under the hood, and some queries
26602658
may need the results of previous ones. Because of that, `explain` actually
2661-
executes the query, and then asks for the query plans. For example,
2659+
executes the query, and then asks for the query plans. For example, running:
26622660

26632661
```ruby
26642662
Customer.where(id: 1).includes(:orders).explain

0 commit comments

Comments
 (0)