diff --git a/README.md b/README.md index 7215b47..25c29a1 100644 --- a/README.md +++ b/README.md @@ -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`.