You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-3Lines changed: 17 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# Save and restore query plans in PostgreSQL
2
2
3
+
## Rationale
4
+
5
+
sr_plan looks like Oracle Outline system. It can be used to lock the execution plan. It is necessary if you do not trust the planner or able to form a better plan.
6
+
3
7
## Build
4
8
5
9
Dependencies: >= Python 3.2, Mako, pycparser
@@ -31,7 +35,7 @@ If you want to save the query plan is necessary to set the variable:
31
35
```SQL
32
36
setsr_plan.write_mode= true;
33
37
```
34
-
Now plans for all subsequent requests will be stored in the table sr_plans. It must be remembered that all requests will be maintained including duplicates.
38
+
Now plans for all subsequent queries will be stored in the table sr_plans. Don't forget that all queries will be stored including duplicates.
35
39
Making an example query:
36
40
```SQL
37
41
select query_hash from sr_plans where query_hash=10;
@@ -43,12 +47,22 @@ set sr_plan.write_mode = false;
43
47
Now verify that your query is saved:
44
48
```SQL
45
49
select query_hash, enable, valid, query, explain_jsonb_plan(plan) from sr_plans;
1783086253 | f | t | select query_hash from sr_plans where query_hash=10; | Bitmap Heap Scan on sr_plans +
54
+
| | | | Recheck Cond: (query_hash =10) +
55
+
| | | | -> Bitmap Index Scan on sr_plans_query_hash_idx+
56
+
| | | | Index Cond: (query_hash =10) +
57
+
| | | |
58
+
46
59
```
60
+
47
61
explain_jsonb_plan function allows you to display explain execute the plan of which lies in jsonb. By default, all the plans are off, you need enable it:
48
62
```SQL
49
-
update sr_plans set enable=true where query_hash=812619660;
63
+
update sr_plans set enable=true where query_hash=1783086253;
50
64
```
51
-
(812619660 for example only)
65
+
(1783086253 for example only)
52
66
After that, the plan for the query will be taken from the sr_plans.
53
67
54
68
In addition sr plan allows you to save a parameterized query plan. In this case, we have some constants in the query are not essential.
0 commit comments