- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit5c9d863
committed
Avoid mislabeling of lateral references when pulling up a subquery.
If we are pulling up a subquery that's under an outer join, andthe subquery's target list contains a strict expression that usesboth a subquery variable and a lateral-reference variable, it's okayto pull up the expression without wrapping it in a PlaceHolderVar.That's safe because if the subquery variable is forced to NULLby the outer join, the expression result will come out as NULL too,so we don't have to force that outcome by evaluating the expressionbelow the outer join. It'd be correct to wrap in a PHV, but that canlead to very significantly worse plans, since we'd then have to usea nestloop plan to pass down the lateral reference to where theexpression will be evaluated.However, when we do that, we should not mark the lateral referencevariable as being nulled by the outer join, because it isn't afterwe pull up the expression in this way. So the marking logic addedbycb8e50a was incorrect in this detail, leading to "wrongvarnullingrels" errors from the consistency-checking logic insetrefs.c. It seems to be sufficient to just not mark lateralreferences at all in this case. (I have a nagging feeling that morecomplexity may be needed in cases where there are several levels ofouter join, but some attempts to break it with that didn't succeed.)Per report from Bertrand Mamasam. Back-patch to v16, as the previouspatch was.Discussion:https://postgr.es/m/CACZ67_UA_EVrqiFXJu9XK50baEpH=ofEPJswa2kFxg6xuSw-ww@mail.gmail.com1 parent0c01f50 commit5c9d863
File tree
3 files changed
+80
-2
lines changed- src
- backend/optimizer/prep
- test/regress
- expected
- sql
3 files changed
+80
-2
lines changedLines changed: 17 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2611 | 2611 |
| |
2612 | 2612 |
| |
2613 | 2613 |
| |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
2614 | 2625 |
| |
2615 | 2626 |
| |
2616 | 2627 |
| |
| |||
2675 | 2686 |
| |
2676 | 2687 |
| |
2677 | 2688 |
| |
2678 |
| - | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
2679 | 2694 |
| |
2680 |
| - | |
| 2695 | + | |
2681 | 2696 |
| |
2682 | 2697 |
| |
2683 | 2698 |
| |
|
Lines changed: 47 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1750 | 1750 |
| |
1751 | 1751 |
| |
1752 | 1752 |
| |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
1753 | 1800 |
| |
1754 | 1801 |
| |
1755 | 1802 |
| |
|
Lines changed: 16 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
908 | 908 |
| |
909 | 909 |
| |
910 | 910 |
| |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
911 | 927 |
| |
912 | 928 |
| |
913 | 929 |
| |
|
0 commit comments
Comments
(0)