Skip to content

Commit

Permalink
Update active_record_querying.md
Browse files Browse the repository at this point in the history
  • Loading branch information
alonsogarciapablo committed Apr 5, 2024
1 parent dbb5c4a commit 46a1d7f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions guides/source/active_record_querying.md
Expand Up @@ -2610,13 +2610,13 @@ Running EXPLAIN

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

For example, running
For example, running:

```ruby
Customer.where(id: 1).joins(:orders).explain
```

may yield
may yield this for MySQL and MariaDB:

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

under MySQL and MariaDB.

Active Record performs a pretty printing that emulates that of the
corresponding database shell. So, the same query running with the
PostgreSQL adapter would yield instead
PostgreSQL adapter would yield instead:

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

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

```ruby
Customer.where(id: 1).includes(:orders).explain
Expand Down

0 comments on commit 46a1d7f

Please sign in to comment.