forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commited4653d
committed
Further fixing for multi-row VALUES lists for updatable views.
Previously, rewriteTargetListIU() generated a list of attributenumbers from the targetlist, which were passed to rewriteValuesRTE(),which expected them to contain the same number of entries as there arecolumns in the VALUES RTE, and to be in the same order. That was finewhen the target relation was a table, but for an updatable view itcould be broken in at least three different ways ---rewriteTargetListIU() could insert additional targetlist entries forview columns with defaults, the view columns could be in a differentorder from the columns of the underlying base relation, and targetlistentries could be merged together when assigning to elements of anarray or composite type. As a result, when recursing to the baserelation, the list of attribute numbers generated from the rewrittentargetlist could no longer be relied upon to match the columns of theVALUES RTE. We got away with that prior to41531e4 because it usedto always be the case that rewriteValuesRTE() did nothing for theunderlying base relation, since all DEFAULTS had already been replacedwhen it was initially invoked for the view, but that was incorrectbecause it failed to apply defaults from the base relation.Fix this by examining the targetlist entries more carefully andpicking out just those that are simple Vars referencing the VALUESRTE. That's sufficient for the purposes of rewriteValuesRTE(), whichis only responsible for dealing with DEFAULT items in the VALUESRTE. Any DEFAULT item in the VALUES RTE that doesn't have a matchingsimple-Var-assignment in the targetlist is an error which we complainabout, but in theory that ought to be impossible.Additionally, move this code into rewriteValuesRTE() to give a clearerseparation of concerns between the 2 functions. There is no need forrewriteTargetListIU() to know about the details of the VALUES RTE.While at it, fix the comment for rewriteValuesRTE() which claimed thatit doesn't support array element and field assignments --- that hasn'tbeen true sincea3c7a99 (9.6 and later).Back-patch to all supported versions, with minor differences for thepre-9.6 branches, which don't support array element and fieldassignments to the same column in multi-row VALUES lists.Reviewed by Amit Langote.Discussion:https://postgr.es/m/15623-5d67a46788ec8b7f@postgresql.org1 parent3422955 commited4653d
File tree
3 files changed
+106
-43
lines changed- src
- backend/rewrite
- test/regress
- expected
- sql
3 files changed
+106
-43
lines changedLines changed: 59 additions & 39 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
67 | 67 |
| |
68 | 68 |
| |
69 | 69 |
| |
70 |
| - | |
71 |
| - | |
| 70 | + | |
72 | 71 |
| |
73 | 72 |
| |
74 | 73 |
| |
75 | 74 |
| |
76 |
| - | |
77 |
| - | |
| 75 | + | |
| 76 | + | |
78 | 77 |
| |
79 | 78 |
| |
80 | 79 |
| |
| |||
705 | 704 |
| |
706 | 705 |
| |
707 | 706 |
| |
708 |
| - | |
709 |
| - | |
710 |
| - | |
711 |
| - | |
712 |
| - | |
713 | 707 |
| |
714 | 708 |
| |
715 | 709 |
| |
| |||
722 | 716 |
| |
723 | 717 |
| |
724 | 718 |
| |
725 |
| - | |
726 |
| - | |
| 719 | + | |
727 | 720 |
| |
728 | 721 |
| |
729 | 722 |
| |
| |||
734 | 727 |
| |
735 | 728 |
| |
736 | 729 |
| |
737 |
| - | |
738 |
| - | |
739 |
| - | |
740 | 730 |
| |
741 | 731 |
| |
742 | 732 |
| |
| |||
762 | 752 |
| |
763 | 753 |
| |
764 | 754 |
| |
765 |
| - | |
766 |
| - | |
767 |
| - | |
768 |
| - | |
769 | 755 |
| |
770 | 756 |
| |
771 | 757 |
| |
| |||
1240 | 1226 |
| |
1241 | 1227 |
| |
1242 | 1228 |
| |
1243 |
| - | |
1244 |
| - | |
1245 |
| - | |
1246 |
| - | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
1247 | 1235 |
| |
1248 | 1236 |
| |
1249 | 1237 |
| |
1250 | 1238 |
| |
1251 | 1239 |
| |
1252 |
| - | |
1253 |
| - | |
| 1240 | + | |
| 1241 | + | |
1254 | 1242 |
| |
1255 | 1243 |
| |
1256 | 1244 |
| |
1257 | 1245 |
| |
1258 | 1246 |
| |
| 1247 | + | |
| 1248 | + | |
1259 | 1249 |
| |
1260 | 1250 |
| |
1261 | 1251 |
| |
| |||
1268 | 1258 |
| |
1269 | 1259 |
| |
1270 | 1260 |
| |
1271 |
| - | |
1272 |
| - | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
1273 | 1288 |
| |
1274 | 1289 |
| |
1275 | 1290 |
| |
| |||
1320 | 1335 |
| |
1321 | 1336 |
| |
1322 | 1337 |
| |
1323 |
| - | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
1324 | 1341 |
| |
1325 |
| - | |
| 1342 | + | |
| 1343 | + | |
1326 | 1344 |
| |
1327 | 1345 |
| |
1328 |
| - | |
| 1346 | + | |
1329 | 1347 |
| |
1330 | 1348 |
| |
1331 | 1349 |
| |
1332 | 1350 |
| |
1333 | 1351 |
| |
1334 | 1352 |
| |
| 1353 | + | |
| 1354 | + | |
1335 | 1355 |
| |
1336 | 1356 |
| |
1337 | 1357 |
| |
| |||
1379 | 1399 |
| |
1380 | 1400 |
| |
1381 | 1401 |
| |
| 1402 | + | |
| 1403 | + | |
1382 | 1404 |
| |
1383 | 1405 |
| |
1384 | 1406 |
| |
| |||
3467 | 3489 |
| |
3468 | 3490 |
| |
3469 | 3491 |
| |
3470 |
| - | |
3471 | 3492 |
| |
3472 | 3493 |
| |
3473 | 3494 |
| |
| |||
3517 | 3538 |
| |
3518 | 3539 |
| |
3519 | 3540 |
| |
3520 |
| - | |
3521 |
| - | |
| 3541 | + | |
3522 | 3542 |
| |
3523 |
| - | |
3524 |
| - | |
| 3543 | + | |
| 3544 | + | |
3525 | 3545 |
| |
3526 | 3546 |
| |
3527 | 3547 |
| |
| |||
3532 | 3552 |
| |
3533 | 3553 |
| |
3534 | 3554 |
| |
3535 |
| - | |
| 3555 | + | |
3536 | 3556 |
| |
3537 | 3557 |
| |
3538 | 3558 |
| |
| |||
3543 | 3563 |
| |
3544 | 3564 |
| |
3545 | 3565 |
| |
3546 |
| - | |
3547 |
| - | |
| 3566 | + | |
3548 | 3567 |
| |
3549 | 3568 |
| |
3550 | 3569 |
| |
| |||
3554 | 3573 |
| |
3555 | 3574 |
| |
3556 | 3575 |
| |
3557 |
| - | |
| 3576 | + | |
3558 | 3577 |
| |
3559 | 3578 |
| |
3560 | 3579 |
| |
| |||
3599 | 3618 |
| |
3600 | 3619 |
| |
3601 | 3620 |
| |
3602 |
| - | |
| 3621 | + | |
| 3622 | + | |
3603 | 3623 |
| |
3604 | 3624 |
| |
3605 | 3625 |
| |
|
Lines changed: 33 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2791 | 2791 |
| |
2792 | 2792 |
| |
2793 | 2793 |
| |
| 2794 | + | |
2794 | 2795 |
| |
2795 | 2796 |
| |
2796 | 2797 |
| |
| |||
2806 | 2807 |
| |
2807 | 2808 |
| |
2808 | 2809 |
| |
2809 |
| - | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
2810 | 2813 |
| |
2811 | 2814 |
| |
2812 | 2815 |
| |
| |||
2832 | 2835 |
| |
2833 | 2836 |
| |
2834 | 2837 |
| |
| 2838 | + | |
2835 | 2839 |
| |
2836 | 2840 |
| |
2837 | 2841 |
| |
| |||
2847 | 2851 |
| |
2848 | 2852 |
| |
2849 | 2853 |
| |
2850 |
| - | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
2851 | 2857 |
| |
2852 | 2858 |
| |
2853 | 2859 |
| |
| |||
2866 | 2872 |
| |
2867 | 2873 |
| |
2868 | 2874 |
| |
| 2875 | + | |
2869 | 2876 |
| |
2870 | 2877 |
| |
2871 | 2878 |
| |
| |||
2881 | 2888 |
| |
2882 | 2889 |
| |
2883 | 2890 |
| |
2884 |
| - | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
2885 | 2894 |
| |
2886 | 2895 |
| |
2887 | 2896 |
| |
| |||
2902 | 2911 |
| |
2903 | 2912 |
| |
2904 | 2913 |
| |
| 2914 | + | |
2905 | 2915 |
| |
2906 | 2916 |
| |
2907 | 2917 |
| |
| |||
2923 | 2933 |
| |
2924 | 2934 |
| |
2925 | 2935 |
| |
2926 |
| - | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
2927 | 2941 |
| |
2928 | 2942 |
| |
2929 | 2943 |
| |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + |
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1400 | 1400 |
| |
1401 | 1401 |
| |
1402 | 1402 |
| |
| 1403 | + | |
1403 | 1404 |
| |
1404 | 1405 |
| |
1405 | 1406 |
| |
| |||
1426 | 1427 |
| |
1427 | 1428 |
| |
1428 | 1429 |
| |
| 1430 | + | |
1429 | 1431 |
| |
1430 | 1432 |
| |
1431 | 1433 |
| |
| |||
1445 | 1447 |
| |
1446 | 1448 |
| |
1447 | 1449 |
| |
| 1450 | + | |
1448 | 1451 |
| |
1449 | 1452 |
| |
1450 | 1453 |
| |
| |||
1466 | 1469 |
| |
1467 | 1470 |
| |
1468 | 1471 |
| |
| 1472 | + | |
1469 | 1473 |
| |
1470 | 1474 |
| |
1471 | 1475 |
| |
1472 | 1476 |
| |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + |
0 commit comments
Comments
(0)