Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
ildus committed Dec 17, 2018
1 parent d976efc commit b1a4d0d
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,62 @@ If we keep the plan for the query and enable it to be used also for the followin
select query_hash from sr_plans where query_hash=1000+_p(11);
select query_hash from sr_plans where query_hash=1000+_p(-5);
```

## Explain

It is possible to see saved plans by using `show_plan` function. It requires
knowing query hash which could be fetched from `sr_plans` table.

Examples:

```SQL
SELECT show_plan(1);
show_plan
----------------------------------------------
("Seq Scan on public.explain_test")
(" Output: test_attr1, test_attr2")
(" Filter: (explain_test.test_attr1 = 10)")
(3 rows)
```

Get second plan:

```SQL
SELECT show_plan(1, index := 2);
show_plan
----------------------------------------------
("Seq Scan on public.explain_test")
(" Output: test_attr1, test_attr2")
(" Filter: (explain_test.test_attr1 = 10)")
(3 rows)
```

Use another output format (supported formats are `json`, `text`, `xml`):

```SQL
SELECT show_plan(1, format := 'json');
show_plan
------------------------------------------------------
("[ +
{ +
""Plan"": { +
""Node Type"": ""Seq Scan"", +
""Parallel Aware"": false, +
""Relation Name"": ""explain_test"", +
""Schema"": ""public"", +
""Alias"": ""explain_test"", +
""Output"": [""test_attr1"", ""test_attr2""], +
""Filter"": ""(explain_test.test_attr1 = 10)""+
} +
} +
]")
(1 row)
```

## `pg_stat_statements` integration

`sr_plans` table contains `query_id` columns which could be used to make
joins with `pg_stat_statements` tables and views.

Note: in `shared_preload_libraries` list `pg_stat_statements` should be
specified after `sr_plan`.

0 comments on commit b1a4d0d

Please sign in to comment.