forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7ebb03c
Estimate cost of elided SubqueryScan, Append, MergeAppend nodes better.
setrefs.c contains logic to discard no-op SubqueryScan nodes, that is,ones that have no qual to check and copy the input targetlist unchanged.(Formally it's not very nice to be applying such optimizations so latein the planner, but there are practical reasons for it; mostly that wecan't unify relids between the subquery and the parent query until weflatten the rangetable during setrefs.c.) This behavior falsifies ourprevious cost estimates, since we would've charged cpu_tuple_cost perrow just to pass data through the node. Most of the time that's littleenough to not matter, but there are cases where this effect visiblychanges the plan compared to what you would've gotten with nosub-select.To improve the situation, make the callers of cost_subqueryscan tellit whether they think the targetlist is trivial. cost_subqueryscanalready has the qual list, so it can check the other half of thecondition easily. It could make its own determination of tlisttriviality too, but doing so would be repetitive (for callers thatmay call it several times) or unnecessarily expensive (for callersthat can determine this more cheaply than a general test would do).This isn't a 100% solution, because createplan.c also does thingsthat can falsify any earlier estimate of whether the tlist istrivial. However, it fixes nearly all cases in practice, if resultsfor the regression tests are anything to go by.setrefs.c also contains logic to discard no-op Append and MergeAppendnodes. We did have knowledge of that behavior at costing time, butsomebody failed to update it when a check on parallel-awareness wasadded to the setrefs.c logic. Fix that while we're here.These changes result in two minor changes in query plans shown inour regression tests. Neither is relevant to the purposes of itstest case AFAICT.Patch by me; thanks to Richard Guo for review.Discussion:https://postgr.es/m/2581077.1651703520@sss.pgh.pa.us1 parentbca2d0e commit7ebb03c
File tree
9 files changed
+147
-39
lines changed- src
- backend/optimizer
- path
- plan
- prep
- util
- include/optimizer
- test/regress/expected
9 files changed
+147
-39
lines changedLines changed: 33 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2451 | 2451 |
| |
2452 | 2452 |
| |
2453 | 2453 |
| |
| 2454 | + | |
2454 | 2455 |
| |
2455 | 2456 |
| |
2456 | 2457 |
| |
| |||
2613 | 2614 |
| |
2614 | 2615 |
| |
2615 | 2616 |
| |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
2616 | 2647 |
| |
2617 | 2648 |
| |
2618 | 2649 |
| |
| |||
2631 | 2662 |
| |
2632 | 2663 |
| |
2633 | 2664 |
| |
| 2665 | + | |
2634 | 2666 |
| |
2635 | 2667 |
| |
2636 | 2668 |
| |
| |||
2656 | 2688 |
| |
2657 | 2689 |
| |
2658 | 2690 |
| |
| 2691 | + | |
2659 | 2692 |
| |
2660 | 2693 |
| |
2661 | 2694 |
| |
|
Lines changed: 19 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1415 | 1415 |
| |
1416 | 1416 |
| |
1417 | 1417 |
| |
| 1418 | + | |
1418 | 1419 |
| |
1419 | 1420 |
| |
1420 | 1421 |
| |
1421 |
| - | |
| 1422 | + | |
| 1423 | + | |
1422 | 1424 |
| |
1423 | 1425 |
| |
1424 | 1426 |
| |
| |||
1458 | 1460 |
| |
1459 | 1461 |
| |
1460 | 1462 |
| |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
1461 | 1479 |
| |
1462 | 1480 |
| |
1463 | 1481 |
| |
|
Lines changed: 9 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1636 | 1636 |
| |
1637 | 1637 |
| |
1638 | 1638 |
| |
1639 |
| - | |
1640 |
| - | |
1641 |
| - | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
1642 | 1643 |
| |
1643 | 1644 |
| |
1644 | 1645 |
| |
| |||
1710 | 1711 |
| |
1711 | 1712 |
| |
1712 | 1713 |
| |
1713 |
| - | |
1714 |
| - | |
1715 |
| - | |
1716 |
| - | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
1717 | 1719 |
| |
1718 | 1720 |
| |
1719 | 1721 |
| |
|
Lines changed: 23 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
78 | 78 |
| |
79 | 79 |
| |
80 | 80 |
| |
81 |
| - | |
| 81 | + | |
| 82 | + | |
82 | 83 |
| |
83 | 84 |
| |
84 | 85 |
| |
| |||
226 | 227 |
| |
227 | 228 |
| |
228 | 229 |
| |
| 230 | + | |
229 | 231 |
| |
230 | 232 |
| |
231 | 233 |
| |
| |||
254 | 256 |
| |
255 | 257 |
| |
256 | 258 |
| |
257 |
| - | |
| 259 | + | |
| 260 | + | |
258 | 261 |
| |
259 | 262 |
| |
260 | 263 |
| |
| |||
291 | 294 |
| |
292 | 295 |
| |
293 | 296 |
| |
| 297 | + | |
294 | 298 |
| |
295 | 299 |
| |
296 | 300 |
| |
| |||
309 | 313 |
| |
310 | 314 |
| |
311 | 315 |
| |
| 316 | + | |
312 | 317 |
| |
313 | 318 |
| |
314 | 319 |
| |
| |||
376 | 381 |
| |
377 | 382 |
| |
378 | 383 |
| |
| 384 | + | |
379 | 385 |
| |
380 | 386 |
| |
381 | 387 |
| |
382 | 388 |
| |
383 | 389 |
| |
384 | 390 |
| |
385 | 391 |
| |
386 |
| - | |
| 392 | + | |
| 393 | + | |
387 | 394 |
| |
388 | 395 |
| |
389 | 396 |
| |
| |||
1117 | 1124 |
| |
1118 | 1125 |
| |
1119 | 1126 |
| |
| 1127 | + | |
1120 | 1128 |
| |
1121 | 1129 |
| |
1122 | 1130 |
| |
1123 | 1131 |
| |
1124 | 1132 |
| |
1125 | 1133 |
| |
1126 | 1134 |
| |
1127 |
| - | |
| 1135 | + | |
| 1136 | + | |
1128 | 1137 |
| |
1129 | 1138 |
| |
1130 | 1139 |
| |
| |||
1135 | 1144 |
| |
1136 | 1145 |
| |
1137 | 1146 |
| |
| 1147 | + | |
| 1148 | + | |
1138 | 1149 |
| |
1139 | 1150 |
| |
1140 | 1151 |
| |
| |||
1160 | 1171 |
| |
1161 | 1172 |
| |
1162 | 1173 |
| |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
1163 | 1177 |
| |
1164 | 1178 |
| |
1165 | 1179 |
| |
| |||
1185 | 1199 |
| |
1186 | 1200 |
| |
1187 | 1201 |
| |
| 1202 | + | |
1188 | 1203 |
| |
1189 | 1204 |
| |
1190 | 1205 |
| |
| |||
1199 | 1214 |
| |
1200 | 1215 |
| |
1201 | 1216 |
| |
| 1217 | + | |
1202 | 1218 |
| |
1203 | 1219 |
| |
1204 | 1220 |
| |
| 1221 | + | |
| 1222 | + | |
1205 | 1223 |
| |
1206 | 1224 |
| |
1207 | 1225 |
| |
| |||
1234 | 1252 |
| |
1235 | 1253 |
| |
1236 | 1254 |
| |
| 1255 | + | |
1237 | 1256 |
| |
1238 | 1257 |
| |
1239 | 1258 |
| |
|
Lines changed: 44 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1326 | 1326 |
| |
1327 | 1327 |
| |
1328 | 1328 |
| |
1329 |
| - | |
1330 |
| - | |
1331 |
| - | |
1332 |
| - | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
1333 | 1336 |
| |
1334 | 1337 |
| |
1335 | 1338 |
| |
1336 | 1339 |
| |
1337 | 1340 |
| |
1338 | 1341 |
| |
1339 |
| - | |
1340 |
| - | |
1341 |
| - | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1342 | 1351 |
| |
1343 | 1352 |
| |
1344 | 1353 |
| |
| |||
1476 | 1485 |
| |
1477 | 1486 |
| |
1478 | 1487 |
| |
1479 |
| - | |
1480 |
| - | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
1481 | 1491 |
| |
1482 |
| - | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
1483 | 1495 |
| |
1484 | 1496 |
| |
1485 | 1497 |
| |
| |||
1986 | 1998 |
| |
1987 | 1999 |
| |
1988 | 2000 |
| |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
1989 | 2006 |
| |
1990 | 2007 |
| |
1991 | 2008 |
| |
| 2009 | + | |
1992 | 2010 |
| |
1993 | 2011 |
| |
1994 | 2012 |
| |
| |||
2005 | 2023 |
| |
2006 | 2024 |
| |
2007 | 2025 |
| |
2008 |
| - | |
| 2026 | + | |
| 2027 | + | |
2009 | 2028 |
| |
2010 | 2029 |
| |
2011 | 2030 |
| |
| |||
3901 | 3920 |
| |
3902 | 3921 |
| |
3903 | 3922 |
| |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
| 3929 | + | |
| 3930 | + | |
| 3931 | + | |
| 3932 | + | |
| 3933 | + | |
| 3934 | + | |
3904 | 3935 |
| |
3905 | 3936 |
| |
3906 | 3937 |
| |
3907 |
| - | |
| 3938 | + | |
| 3939 | + | |
3908 | 3940 |
| |
3909 | 3941 |
| |
3910 | 3942 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
91 | 91 |
| |
92 | 92 |
| |
93 | 93 |
| |
94 |
| - | |
| 94 | + | |
| 95 | + | |
95 | 96 |
| |
96 | 97 |
| |
97 | 98 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
106 |
| - | |
107 |
| - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
108 | 111 |
| |
109 | 112 |
| |
110 | 113 |
| |
|
0 commit comments
Comments
(0)