forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork0
Commite7c02a5
committed
Fix planner failures with overlapping mergejoin clauses in an outer join.
Given overlapping or partially redundant join clauses, for examplet1 JOIN t2 ON t1.a = t2.x AND t1.b = t2.xthe planner's EquivalenceClass machinery will ordinarily refactor theclauses as "t1.a = t1.b AND t1.a = t2.x", so that join processing doesn'tsee multiple references to the same EquivalenceClass in a list of joinequality clauses. However, if the join is outer, it's incorrect to derivea restriction clause on the outer side from the join conditions, so theclause refactoring does not happen and we end up with overlapping joinconditions. The code that attempted to deal with such cases had severalsubtle bugs, which could result in "left and right pathkeys do not match inmergejoin" or "outer pathkeys do not match mergeclauses" planner errors,if the selected join plan type was a mergejoin. (It does not appear thatany actually incorrect plan could have been emitted.)The core of the problem really was failure to recognize that the outer andinner relations' pathkeys have different relationships to the mergeclauselist. A join's mergeclause list is constructed by reference to the outerpathkeys, so it will always be ordered the same as the outer pathkeys, butthis cannot be presumed true for the inner pathkeys. If the inner sides ofthe mergeclauses contain multiple references to the same EquivalenceClass({t2.x} in the above example) then a simplistic rendering of the requiredinner sort order is like "ORDER BY t2.x, t2.x", but the pathkey machineryrecognizes that the second sort column is redundant and throws it away.The mergejoin planning code failed to account for that behavior properly.One error was to try to generate cut-down versions of the mergeclause listfrom cut-down versions of the inner pathkeys in the same way as the initialconstruction of the mergeclause list from the outer pathkeys was done; thiscould lead to choosing a mergeclause list that fails to match the outerpathkeys. The other problem was that the pathkey cross-checking code increate_mergejoin_plan treated the inner and outer pathkey listsidentically, whereas actually the expectations for them must be different.That led to false "pathkeys do not match" failures in some cases, and inprinciple could have led to failure to detect bogus plans in other cases,though there is no indication that such bogus plans could be generated.Reported by Alexander Kuzmenkov, who also reviewed this patch. This hasbeen broken for years (back to around 8.3 according to my testing), soback-patch to all supported branches.Discussion:https://postgr.es/m/5dad9160-4632-0e47-e120-8e2082000c01@postgrespro.ru1 parent83fce67 commite7c02a5
File tree
6 files changed
+322
-124
lines changed- src
- backend/optimizer
- path
- plan
- include/optimizer
- test/regress
- expected
- sql
6 files changed
+322
-124
lines changedLines changed: 14 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
739 | 739 |
| |
740 | 740 |
| |
741 | 741 |
| |
742 |
| - | |
743 |
| - | |
744 |
| - | |
745 |
| - | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
746 | 746 |
| |
747 | 747 |
| |
748 | 748 |
| |
| |||
987 | 987 |
| |
988 | 988 |
| |
989 | 989 |
| |
990 |
| - | |
991 |
| - | |
992 |
| - | |
993 |
| - | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
994 | 994 |
| |
995 | 995 |
| |
996 | 996 |
| |
| |||
1110 | 1110 |
| |
1111 | 1111 |
| |
1112 | 1112 |
| |
1113 |
| - | |
1114 |
| - | |
1115 |
| - | |
1116 |
| - | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1117 | 1116 |
| |
1118 | 1117 |
| |
1119 | 1118 |
| |
| |||
1152 | 1151 |
| |
1153 | 1152 |
| |
1154 | 1153 |
| |
1155 |
| - | |
1156 |
| - | |
1157 |
| - | |
1158 |
| - | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
1159 | 1157 |
| |
1160 | 1158 |
| |
1161 | 1159 |
| |
|
Lines changed: 121 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
941 | 941 |
| |
942 | 942 |
| |
943 | 943 |
| |
944 |
| - | |
945 |
| - | |
946 |
| - | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
947 | 947 |
| |
948 | 948 |
| |
949 |
| - | |
950 |
| - | |
951 |
| - | |
| 949 | + | |
952 | 950 |
| |
953 |
| - | |
| 951 | + | |
954 | 952 |
| |
955 | 953 |
| |
956 | 954 |
| |
957 | 955 |
| |
958 | 956 |
| |
959 | 957 |
| |
960 | 958 |
| |
| 959 | + | |
961 | 960 |
| |
962 | 961 |
| |
963 |
| - | |
964 |
| - | |
965 |
| - | |
966 |
| - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
967 | 965 |
| |
968 | 966 |
| |
969 | 967 |
| |
| |||
1004 | 1002 |
| |
1005 | 1003 |
| |
1006 | 1004 |
| |
1007 |
| - | |
1008 |
| - | |
| 1005 | + | |
| 1006 | + | |
1009 | 1007 |
| |
1010 | 1008 |
| |
1011 | 1009 |
| |
1012 |
| - | |
| 1010 | + | |
1013 | 1011 |
| |
1014 | 1012 |
| |
1015 |
| - | |
1016 |
| - | |
1017 |
| - | |
1018 |
| - | |
1019 |
| - | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
1020 | 1019 |
| |
1021 | 1020 |
| |
1022 | 1021 |
| |
1023 | 1022 |
| |
1024 | 1023 |
| |
1025 | 1024 |
| |
1026 | 1025 |
| |
1027 |
| - | |
1028 |
| - | |
1029 |
| - | |
1030 |
| - | |
1031 |
| - | |
1032 |
| - | |
| 1026 | + | |
| 1027 | + | |
1033 | 1028 |
| |
1034 | 1029 |
| |
1035 | 1030 |
| |
| |||
1233 | 1228 |
| |
1234 | 1229 |
| |
1235 | 1230 |
| |
1236 |
| - | |
1237 |
| - | |
| 1231 | + | |
| 1232 | + | |
1238 | 1233 |
| |
1239 | 1234 |
| |
1240 | 1235 |
| |
| |||
1311 | 1306 |
| |
1312 | 1307 |
| |
1313 | 1308 |
| |
1314 |
| - | |
1315 |
| - | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
1316 | 1316 |
| |
1317 | 1317 |
| |
1318 | 1318 |
| |
| |||
1321 | 1321 |
| |
1322 | 1322 |
| |
1323 | 1323 |
| |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
1324 | 1416 |
| |
1325 | 1417 |
| |
1326 | 1418 |
| |
|
0 commit comments
Comments
(0)