forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit24c19e9
committed
Repair issues with faulty generation of merge-append plans.
create_merge_append_plan failed to honor the CP_EXACT_TLIST flag:it would generate the expected targetlist but then it felt free toadd resjunk sort targets to it. This demonstrably leads to assertionfailures in v11 and HEAD, and it's probably just accidental that wedon't see the same in older branches. I've not looked into whetherthere would be any real-world consequences in non-assert builds.In HEAD, create_append_plan has sprouted the same problem, so fixthat too (although we do not have any test cases that seem able toreach that bug). This is an oversight in commit3fc6e2d whichinvented the CP_EXACT_TLIST flag, so back-patch to 9.6 where thatcame in.convert_subquery_pathkeys would create pathkeys for subquery outputvalues if they match any EquivalenceClass known in the outer queryand are available in the subquery's syntactic targetlist. However,the second part of that condition is wrong, because such values mightnot appear in the subquery relation's reltarget list, which wouldmean that they couldn't be accessed above the level of the subqueryscan. We must check that they appear in the reltarget list, instead.This can lead to dropping knowledge about the subquery's sortordering, but I believe it's okay, because any sort key that theouter query actually has any interest in would appear in thereltarget list.This second issue is of very long standing, but right now there's noevidence that it causes observable problems before 9.6, so I refrainedfrom back-patching further than that. We can revisit that choice ifsomebody finds a way to make it cause problems in older branches.(Developing useful test cases for these issues is really problematic;fixing convert_subquery_pathkeys removes the only known way to exhibitthe create_merge_append_plan bug, and neither of the test cases addedby this patch causes a problem in all branches, even when consideringthe issues separately.)The second issue explains bug #15795 from Suresh Kumar R ("could notfind pathkey item to sort" with nested DISTINCT queries). I stumbledacross the first issue while investigating that.Discussion:https://postgr.es/m/15795-fadb56c8e44ee73c@postgresql.org1 parent64084d6 commit24c19e9
File tree
4 files changed
+208
-30
lines changed- src
- backend/optimizer
- path
- plan
- test/regress
- expected
- sql
4 files changed
+208
-30
lines changedLines changed: 52 additions & 20 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
| 36 | + | |
36 | 37 |
| |
37 | 38 |
| |
38 | 39 |
| |
| |||
771 | 772 |
| |
772 | 773 |
| |
773 | 774 |
| |
774 |
| - | |
775 |
| - | |
776 |
| - | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
777 | 780 |
| |
778 | 781 |
| |
779 | 782 |
| |
| |||
799 | 802 |
| |
800 | 803 |
| |
801 | 804 |
| |
| 805 | + | |
802 | 806 |
| |
803 | 807 |
| |
804 | 808 |
| |
805 | 809 |
| |
806 | 810 |
| |
807 |
| - | |
808 |
| - | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
809 | 814 |
| |
810 | 815 |
| |
811 | 816 |
| |
812 |
| - | |
813 | 817 |
| |
814 | 818 |
| |
815 | 819 |
| |
816 | 820 |
| |
817 |
| - | |
818 | 821 |
| |
819 | 822 |
| |
820 | 823 |
| |
| |||
828 | 831 |
| |
829 | 832 |
| |
830 | 833 |
| |
831 |
| - | |
| 834 | + | |
832 | 835 |
| |
833 | 836 |
| |
834 | 837 |
| |
| |||
885 | 888 |
| |
886 | 889 |
| |
887 | 890 |
| |
| 891 | + | |
888 | 892 |
| |
889 |
| - | |
890 | 893 |
| |
891 | 894 |
| |
892 | 895 |
| |
893 | 896 |
| |
894 |
| - | |
895 |
| - | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
896 | 900 |
| |
897 | 901 |
| |
898 | 902 |
| |
| |||
907 | 911 |
| |
908 | 912 |
| |
909 | 913 |
| |
910 |
| - | |
911 |
| - | |
912 |
| - | |
913 |
| - | |
914 |
| - | |
915 |
| - | |
916 |
| - | |
917 |
| - | |
| 914 | + | |
918 | 915 |
| |
919 |
| - | |
| 916 | + | |
920 | 917 |
| |
921 | 918 |
| |
922 | 919 |
| |
| |||
973 | 970 |
| |
974 | 971 |
| |
975 | 972 |
| |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
976 | 1008 |
| |
977 | 1009 |
| |
978 | 1010 |
| |
|
Lines changed: 55 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
84 |
| - | |
85 |
| - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
86 | 88 |
| |
87 | 89 |
| |
88 | 90 |
| |
| |||
390 | 392 |
| |
391 | 393 |
| |
392 | 394 |
| |
393 |
| - | |
| 395 | + | |
| 396 | + | |
394 | 397 |
| |
395 | 398 |
| |
396 | 399 |
| |
397 |
| - | |
| 400 | + | |
| 401 | + | |
398 | 402 |
| |
399 | 403 |
| |
400 | 404 |
| |
| |||
1054 | 1058 |
| |
1055 | 1059 |
| |
1056 | 1060 |
| |
1057 |
| - | |
| 1061 | + | |
1058 | 1062 |
| |
1059 | 1063 |
| |
1060 | 1064 |
| |
| 1065 | + | |
| 1066 | + | |
1061 | 1067 |
| |
1062 | 1068 |
| |
1063 | 1069 |
| |
| |||
1112 | 1118 |
| |
1113 | 1119 |
| |
1114 | 1120 |
| |
1115 |
| - | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
1116 | 1127 |
| |
1117 | 1128 |
| |
1118 | 1129 |
| |
| |||
1122 | 1133 |
| |
1123 | 1134 |
| |
1124 | 1135 |
| |
| 1136 | + | |
1125 | 1137 |
| |
1126 | 1138 |
| |
1127 | 1139 |
| |
| |||
1231 | 1243 |
| |
1232 | 1244 |
| |
1233 | 1245 |
| |
1234 |
| - | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
1235 | 1260 |
| |
1236 | 1261 |
| |
1237 | 1262 |
| |
| |||
1242 | 1267 |
| |
1243 | 1268 |
| |
1244 | 1269 |
| |
1245 |
| - | |
| 1270 | + | |
| 1271 | + | |
1246 | 1272 |
| |
1247 | 1273 |
| |
1248 | 1274 |
| |
1249 | 1275 |
| |
| 1276 | + | |
| 1277 | + | |
1250 | 1278 |
| |
1251 | 1279 |
| |
1252 | 1280 |
| |
| |||
1265 | 1293 |
| |
1266 | 1294 |
| |
1267 | 1295 |
| |
1268 |
| - | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
1269 | 1302 |
| |
1270 | 1303 |
| |
1271 | 1304 |
| |
| |||
1275 | 1308 |
| |
1276 | 1309 |
| |
1277 | 1310 |
| |
| 1311 | + | |
1278 | 1312 |
| |
1279 | 1313 |
| |
1280 | 1314 |
| |
| |||
1371 | 1405 |
| |
1372 | 1406 |
| |
1373 | 1407 |
| |
1374 |
| - | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1375 | 1420 |
| |
1376 | 1421 |
| |
1377 | 1422 |
| |
|
Lines changed: 73 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
915 | 915 |
| |
916 | 916 |
| |
917 | 917 |
| |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
918 | 991 |
| |
919 | 992 |
| |
920 | 993 |
| |
|
Lines changed: 28 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
379 | 379 |
| |
380 | 380 |
| |
381 | 381 |
| |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
382 | 410 |
| |
383 | 411 |
| |
384 | 412 |
| |
|
0 commit comments
Comments
(0)