Skip to content

Commit fedb779

Browse files
boddhisattvazzak
andcommitted
Add a note about of Postgres buffers option
Co-authored-by: Mohnish G J <[email protected]> Co-authored-by: zzak <[email protected]>
1 parent 193724a commit fedb779

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

guides/source/active_record_postgresql.md

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -808,39 +808,20 @@ For example, to exclude comments from your structure dump, add this to an initia
808808
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ["--no-comments"]
809809
```
810810

811-
Explain options to give deeper insight into Query Performance
812-
--------------
813-
814-
### Buffer
815-
816-
The Buffer option that comes with PostgreSQL's `Explain` command gives one
817-
insights with regard to the data it is reading or writing when performing a
818-
query operation and which of that data comes from cache or another source like
819-
disk.
811+
Explain
812+
-------
820813

821-
The buffer option is intended to give you one or more hints into what
822-
specifically within the query your executing could be a potential cause of
823-
slowness and thereby has room for further improvement.
824-
825-
826-
An example Active Record query that uses `explain` with the `buffers` option:
814+
Along with the standard [`explain`][explain-options] options, the PostgreSQL adapter supports [`buffers`][explain-analayze-buffers].
827815

828816
```ruby
829817
Company.where(id: owning_companies_ids).explain(:analyze, :buffers)
818+
#=> EXPLAIN (ANALYZE, BUFFERS) SELECT "companies".* FROM "companies"
819+
# ...
820+
# Seq Scan on companies (cost=0.00..2.21 rows=3 width=64)
821+
# ...
830822
```
831823

832-
Output of above query:
824+
See their documentation for more details.
833825

834-
```sql
835-
=> EXPLAIN (ANALYZE, BUFFERS) SELECT "companies".* FROM "companies"
836-
WHERE "companies"."id" IN ($1, $2, $3) [["id", 365], ["id", 364], ["id", 360]]
837-
QUERY PLAN
838-
-------------------------------------------------------------------------------
839-
Seq Scan on companies (cost=0.00..2.21 rows=3 width=64)
840-
(actual time=0.009..0.012 rows=3 loops=1)
841-
Filter: (id = ANY ('{365,364,360}'::bigint[]))
842-
Rows Removed by Filter: 10
843-
Buffers: shared hit=1
844-
Planning Time: 0.023 ms
845-
Execution Time: 0.011 ms
846-
```
826+
[explain-options]: active_record_querying.html#explain-options
827+
[explain-analayze-buffers]: https://www.postgresql.org/docs/current/sql-explain.html

0 commit comments

Comments
 (0)