rails/rails — pull request #6584 by amatsuda (2012-06-01 08:18:57+00:00)
Title: improve readability of AR explain result

AR `explain` returns nicely formatted String, but it looks miserable on our Rails console.

```
> User.where(id: 2).explain
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2
EXPLAIN (0.1ms) EXPLAIN QUERY PLAN SELECT "users".* FROM "users" WHERE "users"."id" = 2
=> "EXPLAIN for: SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = 2\n0|0|0|SEARCH TABLE users USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)\n"
```

With this patch, `explain` returns a `p`-friendly String instance.

```
> User.where(id: 2).explain
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2
EXPLAIN (0.1ms) EXPLAIN QUERY PLAN SELECT "users".* FROM "users" WHERE "users"."id" = 2
=> EXPLAIN for: SELECT "users".* FROM "users" WHERE "users"."id" = 2
0|0|0|SEARCH TABLE users USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
```