forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8e10405
committed
Avoid unnecessary out-of-memory errors during encoding conversion.
Encoding conversion uses the very simplistic rule that the outputcan't be more than 4X longer than the input, and palloc's a bufferof that size. This results in failure to convert any string longerthan 1/4 GB, which is becoming an annoying limitation.As a band-aid to improve matters, allow the allocated output buffersize to exceed 1GB. We still insist that the final result fit intoMaxAllocSize (1GB), though. Perhaps it'd be safe to relax thatrestriction, but it'd require close analysis of all callers, whichis daunting (not least because external modules might call thesefunctions). For the moment, this should allow a 2X to 4X improvementin the longest string we can convert, which is a useful gain inreturn for quite a simple patch.Also, once we have successfully converted a long string, repallocthe output down to the actual string length, returning the excessto the malloc pool. This seems worth doing since we can usuallyexpect to give back several MB if we take this path at all.This still leaves much to be desired, most notably that the assumptionthat MAX_CONVERSION_GROWTH == 4 is very fragile, and yet we have noguard code verifying that the output buffer isn't overrun. Fixingthat would require significant changes in the encoding conversionAPIs, so it'll have to wait for some other day.The present patch seems safely back-patchable, so patch all supportedbranches.Alvaro Herrera and Tom LaneDiscussion:https://postgr.es/m/20190816181418.GA898@alvherre.pgsqlDiscussion:https://postgr.es/m/3614.1569359690@sss.pgh.pa.us1 parentc477f3e commit8e10405
1 file changed
+56
-6
lines changedLines changed: 56 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
349 | 349 |
| |
350 | 350 |
| |
351 | 351 |
| |
352 |
| - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
353 | 359 |
| |
354 |
| - | |
| 360 | + | |
355 | 361 |
| |
356 | 362 |
| |
357 | 363 |
| |
358 | 364 |
| |
359 | 365 |
| |
360 | 366 |
| |
361 |
| - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
362 | 370 |
| |
363 | 371 |
| |
364 | 372 |
| |
365 | 373 |
| |
366 | 374 |
| |
367 | 375 |
| |
368 | 376 |
| |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
369 | 397 |
| |
370 | 398 |
| |
371 | 399 |
| |
| |||
682 | 710 |
| |
683 | 711 |
| |
684 | 712 |
| |
685 |
| - | |
| 713 | + | |
| 714 | + | |
686 | 715 |
| |
687 |
| - | |
| 716 | + | |
688 | 717 |
| |
689 | 718 |
| |
690 | 719 |
| |
691 | 720 |
| |
692 | 721 |
| |
693 | 722 |
| |
694 |
| - | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
695 | 726 |
| |
696 | 727 |
| |
697 | 728 |
| |
698 | 729 |
| |
699 | 730 |
| |
700 | 731 |
| |
701 | 732 |
| |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
702 | 752 |
| |
703 | 753 |
| |
704 | 754 |
| |
|
0 commit comments
Comments
(0)