Commit cb8e50a
committed
Avoid inserting PlaceHolderVars in cases where pre-v16 PG did not.
Commit 2489d76 removed some logic from pullup_replace_vars()
that avoided wrapping a PlaceHolderVar around a pulled-up
subquery output expression if the expression could be proven
to go to NULL anyway (because it contained Vars or PHVs of the
pulled-up relation and did not contain non-strict constructs).
But removing that logic turns out to cause performance regressions
in some cases, because the extra PHV blocks subexpression folding,
and will do so even if outer-join reduction later turns it into a
no-op with no phnullingrels bits. This can for example prevent
an expression from being matched to an index.
The reason for always adding a PHV was to ensure we had someplace
to put the varnullingrels marker bits of the Var being replaced.
However, it turns out we can optimize in exactly the same cases that
the previous code did, because we can instead attach the needed
varnullingrels bits to the contained Var(s)/PHV(s).
This is not a complete solution --- it would be even better if we
could remove PHVs after reducing them to no-ops. It doesn't look
practical to back-patch such an improvement, but this change seems
safe and at least gets rid of the performance-regression cases.
Per complaint from Nikhil Raj. Back-patch to v16 where the
problem appeared.
Discussion: https://postgr.es/m/CAG1ps1xvnTZceKK24OUfMKLPvDP2vjT-d+F2AOCWbw_v3KeEgg@mail.gmail.com1 parent 3409b4d commit cb8e50a
File tree
4 files changed
+107
-15
lines changed- src
- backend
- optimizer/prep
- rewrite
- test/regress
- expected
- sql
4 files changed
+107
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2490 | 2490 | | |
2491 | 2491 | | |
2492 | 2492 | | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
2493 | 2498 | | |
2494 | 2499 | | |
2495 | 2500 | | |
2496 | | - | |
2497 | | - | |
2498 | | - | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
2499 | 2520 | | |
2500 | | - | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
2501 | 2535 | | |
2502 | 2536 | | |
2503 | 2537 | | |
| |||
2518 | 2552 | | |
2519 | 2553 | | |
2520 | 2554 | | |
2521 | | - | |
2522 | | - | |
2523 | | - | |
2524 | | - | |
2525 | | - | |
| 2555 | + | |
2526 | 2556 | | |
2527 | 2557 | | |
2528 | 2558 | | |
2529 | 2559 | | |
2530 | 2560 | | |
2531 | 2561 | | |
2532 | | - | |
| 2562 | + | |
2533 | 2563 | | |
2534 | 2564 | | |
2535 | 2565 | | |
2536 | 2566 | | |
2537 | 2567 | | |
2538 | 2568 | | |
2539 | 2569 | | |
2540 | | - | |
| 2570 | + | |
2541 | 2571 | | |
2542 | 2572 | | |
2543 | 2573 | | |
2544 | 2574 | | |
2545 | | - | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
2546 | 2584 | | |
2547 | 2585 | | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
2548 | 2590 | | |
2549 | 2591 | | |
2550 | 2592 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1141 | 1141 | | |
1142 | 1142 | | |
1143 | 1143 | | |
1144 | | - | |
| 1144 | + | |
| 1145 | + | |
1145 | 1146 | | |
1146 | 1147 | | |
1147 | 1148 | | |
| |||
1170 | 1171 | | |
1171 | 1172 | | |
1172 | 1173 | | |
1173 | | - | |
| 1174 | + | |
| 1175 | + | |
1174 | 1176 | | |
1175 | 1177 | | |
1176 | 1178 | | |
| |||
1188 | 1190 | | |
1189 | 1191 | | |
1190 | 1192 | | |
1191 | | - | |
| 1193 | + | |
| 1194 | + | |
1192 | 1195 | | |
1193 | 1196 | | |
1194 | 1197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1721 | 1721 | | |
1722 | 1722 | | |
1723 | 1723 | | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
1724 | 1753 | | |
1725 | 1754 | | |
1726 | 1755 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
890 | 890 | | |
891 | 891 | | |
892 | 892 | | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
893 | 911 | | |
894 | 912 | | |
895 | 913 | | |
| |||
0 commit comments