- Notifications
You must be signed in to change notification settings - Fork5
Commitc7b849a
committed
Prevent leakage of cached plans and execution trees in plpgsql DO blocks.
plpgsql likes to cache query plans and simple-expression execution statetrees across calls. This is a considerable win for multiple executionsof the same function. However, it's useless for DO blocks, since bydefinition those are executed only once and discarded. Nonetheless,we were allowing a DO block's expression execution trees to surviveuntil end of transaction, resulting in a significant intra-transactionmemory leak, as reported by Yeb Havinga. Worse, if the DO block exitedwith an error, the compiled form of the block's code was leaked tillend of session --- along with subsidiary plancache entries.To fix, make DO blocks keep their expression execution trees in a privateEState that's deleted at exit from the block, and add a PG_TRY blockto plpgsql_inline_handler to make sure that memory cleanup happenseven on error exits. Also add a regression test covering error handlingin a DO block, because my first try at this broke that. (The test isnot meant to prove that we don't leak memory anymore, though it couldbe used for that with a much larger loop count.)Ideally we'd back-patch this into all versions supporting DO blocks;but the patch needs to add a field to struct PLpgSQL_execstate, and thatwould break ABI compatibility for third-party plugins such as the plpgsqldebugger. Given the small number of complaints so far, fixing this inHEAD only seems like an acceptable choice.1 parent80e3a47 commitc7b849a
File tree
5 files changed
+150
-22
lines changed- src
- pl/plpgsql/src
- test/regress
- expected
- sql
5 files changed
+150
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
69 | 78 | | |
70 | 79 | | |
71 | 80 | | |
| |||
74 | 83 | | |
75 | 84 | | |
76 | 85 | | |
77 | | - | |
| 86 | + | |
78 | 87 | | |
79 | 88 | | |
80 | 89 | | |
| |||
136 | 145 | | |
137 | 146 | | |
138 | 147 | | |
139 | | - | |
| 148 | + | |
| 149 | + | |
140 | 150 | | |
141 | 151 | | |
142 | 152 | | |
| |||
230 | 240 | | |
231 | 241 | | |
232 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
233 | 249 | | |
234 | 250 | | |
235 | 251 | | |
236 | | - | |
| 252 | + | |
| 253 | + | |
237 | 254 | | |
238 | 255 | | |
239 | 256 | | |
| |||
243 | 260 | | |
244 | 261 | | |
245 | 262 | | |
246 | | - | |
| 263 | + | |
| 264 | + | |
247 | 265 | | |
248 | 266 | | |
249 | 267 | | |
| |||
503 | 521 | | |
504 | 522 | | |
505 | 523 | | |
506 | | - | |
| 524 | + | |
507 | 525 | | |
508 | 526 | | |
509 | 527 | | |
| |||
782 | 800 | | |
783 | 801 | | |
784 | 802 | | |
785 | | - | |
| 803 | + | |
786 | 804 | | |
787 | 805 | | |
788 | 806 | | |
| |||
3087 | 3105 | | |
3088 | 3106 | | |
3089 | 3107 | | |
3090 | | - | |
| 3108 | + | |
| 3109 | + | |
3091 | 3110 | | |
3092 | 3111 | | |
3093 | 3112 | | |
| |||
3126 | 3145 | | |
3127 | 3146 | | |
3128 | 3147 | | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
3129 | 3154 | | |
3130 | 3155 | | |
3131 | 3156 | | |
| |||
5148 | 5173 | | |
5149 | 5174 | | |
5150 | 5175 | | |
5151 | | - | |
| 5176 | + | |
5152 | 5177 | | |
5153 | 5178 | | |
5154 | 5179 | | |
| |||
6190 | 6215 | | |
6191 | 6216 | | |
6192 | 6217 | | |
6193 | | - | |
6194 | | - | |
| 6218 | + | |
| 6219 | + | |
6195 | 6220 | | |
6196 | 6221 | | |
6197 | 6222 | | |
| |||
6203 | 6228 | | |
6204 | 6229 | | |
6205 | 6230 | | |
| 6231 | + | |
| 6232 | + | |
| 6233 | + | |
6206 | 6234 | | |
6207 | | - | |
| 6235 | + | |
6208 | 6236 | | |
6209 | 6237 | | |
6210 | 6238 | | |
| 6239 | + | |
6211 | 6240 | | |
6212 | | - | |
| 6241 | + | |
| 6242 | + | |
6213 | 6243 | | |
6214 | 6244 | | |
6215 | 6245 | | |
6216 | 6246 | | |
6217 | 6247 | | |
6218 | 6248 | | |
6219 | | - | |
| 6249 | + | |
6220 | 6250 | | |
6221 | 6251 | | |
6222 | 6252 | | |
| |||
6275 | 6305 | | |
6276 | 6306 | | |
6277 | 6307 | | |
6278 | | - | |
6279 | | - | |
6280 | | - | |
| 6308 | + | |
| 6309 | + | |
| 6310 | + | |
6281 | 6311 | | |
6282 | 6312 | | |
6283 | 6313 | | |
6284 | 6314 | | |
6285 | | - | |
| 6315 | + | |
6286 | 6316 | | |
6287 | 6317 | | |
6288 | 6318 | | |
| |||
6291 | 6321 | | |
6292 | 6322 | | |
6293 | 6323 | | |
6294 | | - | |
6295 | | - | |
| 6324 | + | |
6296 | 6325 | | |
6297 | 6326 | | |
6298 | 6327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
206 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
207 | 252 | | |
208 | 253 | | |
209 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
773 | 773 | | |
774 | 774 | | |
775 | 775 | | |
| 776 | + | |
776 | 777 | | |
777 | 778 | | |
778 | 779 | | |
779 | 780 | | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
780 | 784 | | |
781 | 785 | | |
782 | 786 | | |
| |||
943 | 947 | | |
944 | 948 | | |
945 | 949 | | |
946 | | - | |
| 950 | + | |
| 951 | + | |
947 | 952 | | |
948 | 953 | | |
949 | 954 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4651 | 4651 | | |
4652 | 4652 | | |
4653 | 4653 | | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
| 4666 | + | |
| 4667 | + | |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
| 4671 | + | |
| 4672 | + | |
| 4673 | + | |
| 4674 | + | |
| 4675 | + | |
| 4676 | + | |
| 4677 | + | |
| 4678 | + | |
| 4679 | + | |
| 4680 | + | |
| 4681 | + | |
| 4682 | + | |
4654 | 4683 | | |
4655 | 4684 | | |
4656 | 4685 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3751 | 3751 | | |
3752 | 3752 | | |
3753 | 3753 | | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
| 3764 | + | |
| 3765 | + | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
3754 | 3774 | | |
3755 | 3775 | | |
3756 | 3776 | | |
| |||
0 commit comments
Comments
(0)