forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitaf33039
committed
Fix worst memory leaks in tqueue.c.
TupleQueueReaderNext() leaks like a sieve if it has to do any tupledisassembly/reconstruction. While we could try to clean up its allocationspiecemeal, it seems like a better idea just to insist that it should be runin a short-lived memory context, so that any transient space goes awayautomatically. I chose to have nodeGather.c switch into its existingper-tuple context before the call, rather than inventing a separatecontext inside tqueue.c.This is sufficient to stop all leakage in the simple case I exhibitedearlier today (see link below), but it does not deal with leaks inducedin more complex cases by tqueue.c's insistence on using TopMemoryContextfor data that it's not actually trying hard to keep track of. That issueis intertwined with another major source of inefficiency, namely failureto cache lookup results across calls, so it seems best to deal with itseparately.In passing, improve some comments, and modify gather_readnext's method fordeciding when it's visited all the readers so that it's more obviouslycorrect. (I'm not actually convinced that the previous code *is*correct in the case of a reader deletion; it certainly seems fragile.)Discussion: <32763.1469821037@sss.pgh.pa.us>1 parentbf4ae68 commitaf33039
File tree
3 files changed
+45
-30
lines changed- src
- backend/executor
- include/executor
3 files changed
+45
-30
lines changedLines changed: 26 additions & 19 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
214 | 214 |
| |
215 | 215 |
| |
216 | 216 |
| |
217 |
| - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
218 | 220 |
| |
| 221 | + | |
219 | 222 |
| |
220 | 223 |
| |
221 | 224 |
| |
| |||
274 | 277 |
| |
275 | 278 |
| |
276 | 279 |
| |
| 280 | + | |
277 | 281 |
| |
278 | 282 |
| |
279 | 283 |
| |
280 | 284 |
| |
281 | 285 |
| |
282 | 286 |
| |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
283 | 291 |
| |
| 292 | + | |
284 | 293 |
| |
285 | 294 |
| |
286 | 295 |
| |
287 | 296 |
| |
288 | 297 |
| |
289 | 298 |
| |
290 | 299 |
| |
291 |
| - | |
292 |
| - | |
| 300 | + | |
293 | 301 |
| |
294 | 302 |
| |
295 | 303 |
| |
| |||
314 | 322 |
| |
315 | 323 |
| |
316 | 324 |
| |
317 |
| - | |
| 325 | + | |
318 | 326 |
| |
319 | 327 |
| |
320 | 328 |
| |
| |||
335 | 343 |
| |
336 | 344 |
| |
337 | 345 |
| |
| 346 | + | |
338 | 347 |
| |
339 | 348 |
| |
340 | 349 |
| |
341 | 350 |
| |
342 | 351 |
| |
343 | 352 |
| |
344 | 353 |
| |
345 |
| - | |
346 |
| - | |
347 |
| - | |
348 |
| - | |
349 |
| - | |
350 |
| - | |
351 |
| - | |
352 |
| - | |
353 |
| - | |
354 |
| - | |
355 |
| - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
356 | 360 |
| |
357 | 361 |
| |
358 | 362 |
| |
| |||
367 | 371 |
| |
368 | 372 |
| |
369 | 373 |
| |
370 |
| - | |
371 |
| - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
372 | 377 |
| |
373 |
| - | |
374 |
| - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
375 | 381 |
| |
376 | 382 |
| |
377 | 383 |
| |
| |||
384 | 390 |
| |
385 | 391 |
| |
386 | 392 |
| |
| 393 | + | |
387 | 394 |
| |
388 | 395 |
| |
389 | 396 |
| |
|
Lines changed: 14 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
524 | 524 |
| |
525 | 525 |
| |
526 | 526 |
| |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
527 | 536 |
| |
528 | 537 |
| |
529 | 538 |
| |
530 |
| - | |
531 |
| - | |
532 |
| - | |
533 |
| - | |
534 | 539 |
| |
535 | 540 |
| |
536 | 541 |
| |
| |||
565 | 570 |
| |
566 | 571 |
| |
567 | 572 |
| |
568 |
| - | |
569 |
| - | |
570 |
| - | |
571 |
| - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
572 | 578 |
| |
573 | 579 |
| |
574 | 580 |
| |
|
Lines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 |
| |
21 | 24 |
| |
22 | 25 |
| |
23 | 26 |
| |
24 |
| - | |
25 | 27 |
| |
26 | 28 |
| |
27 |
| - | |
28 |
| - | |
| 29 | + | |
| 30 | + | |
29 | 31 |
| |
30 | 32 |
| |
31 | 33 |
|
0 commit comments
Comments
(0)