forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita3c7a99
committed
Make INSERT-from-multiple-VALUES-rows handle targetlist indirection better.
Previously, if an INSERT with multiple rows of VALUES had indirection(array subscripting or field selection) in its target-columns list, theparser handled that by applying transformAssignedExpr() to each elementof each VALUES row independently. This led to having ArrayRef assignmentnodes or FieldStore nodes in each row of the VALUES RTE. That works forsimple cases, but in bug #14265 Nuri Boardman points out that it failsif there are multiple assignments to elements/fields of the same targetcolumn. For such cases to work, rewriteTargetListIU() has to nest theArrayRefs or FieldStores together to produce a single expression to beassigned to the column. But it failed to find them in the top-leveltargetlist and issued an error about "multiple assignments to same column".We could possibly fix this by teaching the rewriter to applyrewriteTargetListIU to each VALUES row separately, but that would be messy(it would change the output rowtype of the VALUES RTE, for example) andinefficient. Instead, let's fix the parser so that the VALUES RTE outputsare just the user-specified values, cast to the right type if necessary,and then the ArrayRefs or FieldStores are applied in the top-leveltargetlist to Vars representing the RTE's outputs. This is the sameparsetree representation already used for similar cases with INSERT/SELECTsyntax, so it allows simplifications in ruleutils.c, which no longer needsto treat INSERT-from-multiple-VALUES as its own special case.This implementation works by applying transformAssignedExpr to the VALUESentries as before, and then stripping off any ArrayRefs or FieldStores itadds. With lots of VALUES rows it would be noticeably more efficient tonot add those nodes in the first place. But that's just an optimizationnot a bug fix, and there doesn't seem to be any good way to do it withoutsignificant refactoring. (A non-invasive answer would be to applytransformAssignedExpr + stripping to just the first VALUES row, and thenjust forcibly cast remaining rows to the same data types exposed in thefirst row. But this way would lead to different, not-INSERT-specificerrors being reported in casting failure cases, so it doesn't seem verynice.) So leave that for later; this patch at least isn't making theper-row parsing work worse, and it does make the finished parsetreesmaller, saving rewriter and planner work.Catversion bump because stored rules containing such INSERTs would needto change. Because of that, no back-patch, even though this is a verylong-standing bug.Report: <20160727005725.7438.26021@wrigleys.postgresql.org>Discussion: <9578.1469645245@sss.pgh.pa.us>1 parentef1b5af commita3c7a99
File tree
5 files changed
+205
-49
lines changed- src
- backend
- parser
- utils/adt
- include/catalog
- test/regress
- expected
- sql
5 files changed
+205
-49
lines changedLines changed: 57 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
51 | 51 |
| |
52 | 52 |
| |
53 | 53 |
| |
54 |
| - | |
| 54 | + | |
| 55 | + | |
55 | 56 |
| |
56 | 57 |
| |
57 | 58 |
| |
| |||
619 | 620 |
| |
620 | 621 |
| |
621 | 622 |
| |
622 |
| - | |
| 623 | + | |
| 624 | + | |
623 | 625 |
| |
624 | 626 |
| |
625 | 627 |
| |
| |||
663 | 665 |
| |
664 | 666 |
| |
665 | 667 |
| |
666 |
| - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
667 | 678 |
| |
668 | 679 |
| |
669 |
| - | |
| 680 | + | |
| 681 | + | |
670 | 682 |
| |
671 | 683 |
| |
672 | 684 |
| |
| |||
717 | 729 |
| |
718 | 730 |
| |
719 | 731 |
| |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
720 | 740 |
| |
721 | 741 |
| |
722 | 742 |
| |
| |||
739 | 759 |
| |
740 | 760 |
| |
741 | 761 |
| |
742 |
| - | |
| 762 | + | |
| 763 | + | |
743 | 764 |
| |
744 | 765 |
| |
745 | 766 |
| |
| |||
808 | 829 |
| |
809 | 830 |
| |
810 | 831 |
| |
811 |
| - | |
812 |
| - | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
813 | 838 |
| |
814 | 839 |
| |
815 | 840 |
| |
816 |
| - | |
| 841 | + | |
| 842 | + | |
817 | 843 |
| |
818 | 844 |
| |
819 | 845 |
| |
| |||
879 | 905 |
| |
880 | 906 |
| |
881 | 907 |
| |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
882 | 931 |
| |
883 | 932 |
| |
884 | 933 |
| |
|
Lines changed: 20 additions & 40 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
438 | 438 |
| |
439 | 439 |
| |
440 | 440 |
| |
441 |
| - | |
442 |
| - | |
| 441 | + | |
443 | 442 |
| |
444 | 443 |
| |
445 | 444 |
| |
| |||
4551 | 4550 |
| |
4552 | 4551 |
| |
4553 | 4552 |
| |
4554 |
| - | |
4555 |
| - | |
| 4553 | + | |
4556 | 4554 |
| |
4557 |
| - | |
4558 |
| - | |
| 4555 | + | |
4559 | 4556 |
| |
4560 | 4557 |
| |
4561 | 4558 |
| |
| |||
5512 | 5509 |
| |
5513 | 5510 |
| |
5514 | 5511 |
| |
5515 |
| - | |
5516 | 5512 |
| |
5517 | 5513 |
| |
5518 | 5514 |
| |
| |||
5563 | 5559 |
| |
5564 | 5560 |
| |
5565 | 5561 |
| |
5566 |
| - | |
5567 |
| - | |
5568 |
| - | |
5569 |
| - | |
5570 |
| - | |
5571 |
| - | |
| 5562 | + | |
| 5563 | + | |
5572 | 5564 |
| |
5573 |
| - | |
5574 |
| - | |
5575 |
| - | |
5576 |
| - | |
5577 | 5565 |
| |
5578 | 5566 |
| |
5579 | 5567 |
| |
| |||
5599 | 5587 |
| |
5600 | 5588 |
| |
5601 | 5589 |
| |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
5602 | 5594 |
| |
5603 |
| - | |
5604 |
| - | |
5605 |
| - | |
5606 |
| - | |
5607 |
| - | |
5608 |
| - | |
5609 |
| - | |
5610 |
| - | |
5611 |
| - | |
5612 |
| - | |
5613 |
| - | |
5614 |
| - | |
5615 |
| - | |
| 5595 | + | |
| 5596 | + | |
| 5597 | + | |
5616 | 5598 |
| |
5617 | 5599 |
| |
5618 | 5600 |
| |
| |||
5891 | 5873 |
| |
5892 | 5874 |
| |
5893 | 5875 |
| |
5894 |
| - | |
| 5876 | + | |
5895 | 5877 |
| |
5896 | 5878 |
| |
5897 | 5879 |
| |
| |||
7296 | 7278 |
| |
7297 | 7279 |
| |
7298 | 7280 |
| |
7299 |
| - | |
| 7281 | + | |
7300 | 7282 |
| |
7301 | 7283 |
| |
7302 | 7284 |
| |
| |||
9561 | 9543 |
| |
9562 | 9544 |
| |
9563 | 9545 |
| |
9564 |
| - | |
9565 |
| - | |
9566 |
| - | |
| 9546 | + | |
| 9547 | + | |
| 9548 | + | |
9567 | 9549 |
| |
9568 | 9550 |
| |
9569 |
| - | |
| 9551 | + | |
9570 | 9552 |
| |
9571 | 9553 |
| |
9572 | 9554 |
| |
| |||
9594 | 9576 |
| |
9595 | 9577 |
| |
9596 | 9578 |
| |
9597 |
| - | |
9598 |
| - | |
| 9579 | + | |
9599 | 9580 |
| |
9600 | 9581 |
| |
9601 | 9582 |
| |
| |||
9609 | 9590 |
| |
9610 | 9591 |
| |
9611 | 9592 |
| |
9612 |
| - | |
9613 |
| - | |
| 9593 | + | |
9614 | 9594 |
| |
9615 | 9595 |
| |
9616 | 9596 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
53 | 53 |
| |
54 | 54 |
| |
55 | 55 |
| |
56 |
| - | |
| 56 | + | |
57 | 57 |
| |
58 | 58 |
|
Lines changed: 79 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 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 | + |
Lines changed: 48 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + |
0 commit comments
Comments
(0)