forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit36fb9ef
committed
Detect whether plpgsql assignment targets are "local" variables.
Mark whether the target of a potentially optimizable assignmentis "local", in the sense of being declared inside any exceptionblock that could trap an error thrown from the assignment.(This implies that we needn't preserve the variable's valuein case of an error. This patch doesn't do anything with theknowledge, but the next one will.)Normally, this requires a post-parsing scan of the function'sparse tree, since we don't know while parsing a BEGIN ...construct whether we will find EXCEPTION at its end. However,if there are no BEGIN ... EXCEPTION blocks in the function atall, then all assignments are local, even those to variablesrepresenting function arguments. We optimize that common caseby initializing the target_is_local flags to "true", and fixingthem up with a post-scan only if we found EXCEPTION.Note that variables' default-value expressions are never interestingfor expanded-variable optimization, since they couldn't contain areference to the target variable anyway. But the code is set upto compute their target_param and target_is_local correctly anyway,for consistency and in case someone thinks of a use for that data.I added a bit of plpgsql_dumptree support to help verify that thiscode sets the flags as expected. I also added a plpgsql_dumptreecall in plpgsql_compile_inline. It was at best an oversight that"#option dump" didn't work in a DO block; now it does.Author: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>Reviewed-by: Pavel Borisov <pashkin.elfe@gmail.com>Discussion:https://postgr.es/m/CACxu=vJaKFNsYxooSnW1wEgsAO5u_v1XYBacfVJ14wgJV_PYeg@mail.gmail.com1 parenta654af2 commit36fb9ef
4 files changed
+121
-1
lines changedLines changed: 12 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
371 | 371 |
| |
372 | 372 |
| |
373 | 373 |
| |
| 374 | + | |
374 | 375 |
| |
375 | 376 |
| |
376 | 377 |
| |
| |||
811 | 812 |
| |
812 | 813 |
| |
813 | 814 |
| |
| 815 | + | |
| 816 | + | |
| 817 | + | |
814 | 818 |
| |
815 | 819 |
| |
816 | 820 |
| |
| |||
906 | 910 |
| |
907 | 911 |
| |
908 | 912 |
| |
| 913 | + | |
909 | 914 |
| |
910 | 915 |
| |
911 | 916 |
| |
| |||
962 | 967 |
| |
963 | 968 |
| |
964 | 969 |
| |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
965 | 977 |
| |
966 | 978 |
| |
967 | 979 |
| |
|
Lines changed: 88 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
598 | 598 |
| |
599 | 599 |
| |
600 | 600 |
| |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
601 | 686 |
| |
602 | 687 |
| |
603 | 688 |
| |
| |||
1500 | 1585 |
| |
1501 | 1586 |
| |
1502 | 1587 |
| |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
1503 | 1591 |
| |
1504 | 1592 |
| |
1505 | 1593 |
| |
|
Lines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2328 | 2328 |
| |
2329 | 2329 |
| |
2330 | 2330 |
| |
| 2331 | + | |
| 2332 | + | |
2331 | 2333 |
| |
2332 | 2334 |
| |
2333 | 2335 |
| |
| |||
2673 | 2675 |
| |
2674 | 2676 |
| |
2675 | 2677 |
| |
| 2678 | + | |
2676 | 2679 |
| |
2677 | 2680 |
| |
2678 | 2681 |
| |
| |||
2687 | 2690 |
| |
2688 | 2691 |
| |
2689 | 2692 |
| |
| 2693 | + | |
2690 | 2694 |
| |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
2691 | 2703 |
| |
| 2704 | + | |
2692 | 2705 |
| |
| 2706 | + | |
| 2707 | + | |
2693 | 2708 |
| |
2694 | 2709 |
| |
2695 | 2710 |
| |
|
Lines changed: 6 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
225 | 225 |
| |
226 | 226 |
| |
227 | 227 |
| |
228 |
| - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
229 | 231 |
| |
230 | 232 |
| |
| 233 | + | |
231 | 234 |
| |
232 | 235 |
| |
233 | 236 |
| |
| |||
1014 | 1017 |
| |
1015 | 1018 |
| |
1016 | 1019 |
| |
| 1020 | + | |
1017 | 1021 |
| |
1018 | 1022 |
| |
1019 | 1023 |
| |
| |||
1312 | 1316 |
| |
1313 | 1317 |
| |
1314 | 1318 |
| |
| 1319 | + | |
1315 | 1320 |
| |
1316 | 1321 |
| |
1317 | 1322 |
| |
|
0 commit comments
Comments
(0)