forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit085b6b6
committed
Avoid holding a directory FD open across pg_ls_dir_files() calls.
This coding technique is undesirable because (a) it leaks the FD forthe rest of the transaction if the SRF is not run to completion, and(b) allocated FDs are a scarce resource, but multiple interleaveduses of the relevant functions could eat many such FDs.In v11 and later, a query such as "SELECT pg_ls_waldir() LIMIT 1"yields a warning about the leaked FD, and the only reason there'sno warning in earlier branches is that fd.c didn't whine about suchleaks before commit9cb7db3. Even disregarding the warning, itwouldn't be too hard to run a backend out of FDs with careless useof these SQL functions.Hence, rewrite the function so that it reads the directory withina single call, returning the results as a tuplestore rather thanvia value-per-call mode.There are half a dozen other built-in SRFs with similar problems,but let's fix this one to start with, just to see if the buildfarmfinds anything wrong with the code.In passing, fix bogus error report for stat() failure: it waswhining about the directory when it should be fingering theindividual file. Doubtless a copy-and-paste error.Back-patch to v10 where this function was added.Justin Pryzby, with cosmetic tweaks and test cases by meDiscussion:https://postgr.es/m/20200308173103.GC1357@telsasoft.com1 parentbf68b79 commit085b6b6
File tree
3 files changed
+118
-45
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+118
-45
lines changedLines changed: 52 additions & 45 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
523 | 523 |
| |
524 | 524 |
| |
525 | 525 |
| |
526 |
| - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
527 | 532 |
| |
528 | 533 |
| |
529 | 534 |
| |
530 |
| - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
531 | 540 |
| |
532 |
| - | |
| 541 | + | |
533 | 542 |
| |
534 |
| - | |
535 |
| - | |
536 |
| - | |
537 |
| - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
538 | 553 |
| |
539 |
| - | |
540 |
| - | |
| 554 | + | |
| 555 | + | |
541 | 556 |
| |
542 |
| - | |
| 557 | + | |
| 558 | + | |
543 | 559 |
| |
544 |
| - | |
545 |
| - | |
546 |
| - | |
547 |
| - | |
548 |
| - | |
549 |
| - | |
550 |
| - | |
551 |
| - | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
552 | 565 |
| |
553 |
| - | |
554 |
| - | |
| 566 | + | |
555 | 567 |
| |
556 |
| - | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
557 | 578 |
| |
558 |
| - | |
559 |
| - | |
560 |
| - | |
561 |
| - | |
562 |
| - | |
563 |
| - | |
564 |
| - | |
565 |
| - | |
566 |
| - | |
567 |
| - | |
| 579 | + | |
| 580 | + | |
568 | 581 |
| |
569 |
| - | |
570 |
| - | |
571 |
| - | |
| 582 | + | |
572 | 583 |
| |
573 | 584 |
| |
574 |
| - | |
575 |
| - | |
576 |
| - | |
577 |
| - | |
| 585 | + | |
578 | 586 |
| |
579 | 587 |
| |
580 | 588 |
| |
581 | 589 |
| |
582 | 590 |
| |
583 |
| - | |
584 | 591 |
| |
585 | 592 |
| |
586 | 593 |
| |
587 | 594 |
| |
588 | 595 |
| |
589 | 596 |
| |
590 |
| - | |
| 597 | + | |
591 | 598 |
| |
592 | 599 |
| |
593 | 600 |
| |
594 |
| - | |
| 601 | + | |
595 | 602 |
| |
596 | 603 |
| |
597 | 604 |
| |
| |||
602 | 609 |
| |
603 | 610 |
| |
604 | 611 |
| |
605 |
| - | |
606 |
| - | |
| 612 | + | |
607 | 613 |
| |
608 | 614 |
| |
609 |
| - | |
610 |
| - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
611 | 618 |
| |
612 | 619 |
| |
613 | 620 |
| |
|
Lines changed: 46 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
133 | 133 |
| |
134 | 134 |
| |
135 | 135 |
| |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
136 | 182 |
| |
137 | 183 |
| |
138 | 184 |
| |
|
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
30 | 30 |
| |
31 | 31 |
| |
32 | 32 |
| |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
33 | 53 |
| |
34 | 54 |
| |
35 | 55 |
| |
|
0 commit comments
Comments
(0)