@@ -68,3 +68,62 @@ If we keep the plan for the query and enable it to be used also for the followin
6868select query_hash from sr_plans where query_hash= 1000 + _p(11 );
6969select query_hash from sr_plans where query_hash= 1000 + _p(- 5 );
7070```
71+
72+ ## Explain
73+
74+ It is possible to see saved plans by using ` show_plan ` function. It requires
75+ knowing query hash which could be fetched from ` sr_plans ` table.
76+
77+ Examples:
78+
79+ ``` SQL
80+ SELECT show_plan(1 );
81+ show_plan
82+ -- --------------------------------------------
83+ (" Seq Scan on public.explain_test" )
84+ (" Output: test_attr1, test_attr2" )
85+ (" Filter: (explain_test.test_attr1 = 10)" )
86+ (3 rows)
87+ ```
88+
89+ Get second plan:
90+
91+ ``` SQL
92+ SELECT show_plan(1 , index := 2 );
93+ show_plan
94+ -- --------------------------------------------
95+ (" Seq Scan on public.explain_test" )
96+ (" Output: test_attr1, test_attr2" )
97+ (" Filter: (explain_test.test_attr1 = 10)" )
98+ (3 rows)
99+ ```
100+
101+ Use another output format (supported formats are ` json ` , ` text ` , ` xml ` ):
102+
103+ ``` SQL
104+ SELECT show_plan(1 , format := ' json' );
105+ show_plan
106+ -- ----------------------------------------------------
107+ (" [ +
108+ { +
109+ " " Plan" " : { +
110+ " " Node Type" " : " " Seq Scan" " , +
111+ " " Parallel Aware" " : false, +
112+ " " Relation Name" " : " " explain_test" " , +
113+ " " Schema" " : " " public" " , +
114+ " " Alias" " : " " explain_test" " , +
115+ " " Output" " : [" " test_attr1" " , " " test_attr2" " ], +
116+ " " Filter" " : " " (explain_test.test_attr1 = 10)" " +
117+ } +
118+ } +
119+ ]" )
120+ (1 row)
121+ ```
122+
123+ ## ` pg_stat_statements ` integration
124+
125+ ` sr_plans ` table contains ` query_id ` columns which could be used to make
126+ joins with ` pg_stat_statements ` tables and views.
127+
128+ Note: in ` shared_preload_libraries ` list ` pg_stat_statements ` should be
129+ specified after ` sr_plan ` .
0 commit comments