forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit55dc86e
committed
Fix pull_varnos' miscomputation of relids set for a PlaceHolderVar.
Previously, pull_varnos() took the relids of a PlaceHolderVar as beingequal to the relids in its contents, but that fails to account for thepossibility that we have to postpone evaluation of the PHV due to outerjoins. This could result in a malformed plan. The known cases end uptriggering the "failed to assign all NestLoopParams to plan nodes"sanity check in createplan.c, but other symptoms may be possible.The right value to use is the join level we actually intend to evaluatethe PHV at. We can get that from the ph_eval_at field of the associatedPlaceHolderInfo. However, there are some places that call pull_varnos()before the PlaceHolderInfos have been created; in that case, fall backto the conservative assumption that the PHV will be evaluated at itssyntactic level. (In principle this might result in missing some legaloptimization, but I'm not aware of any cases where it's an issue inpractice.) Things are also a bit ticklish for calls occurring duringdeconstruct_jointree(), but AFAICS the ph_eval_at fields should havereached their final values by the time we need them.The main problem in making this work is that pull_varnos() has noway to get at the PlaceHolderInfos. We can fix that easily, if abit tediously, in HEAD by passing it the planner "root" pointer.In the back branches that'd cause an unacceptable API/ABI break forextensions, so leave the existing entry points alone and add new oneswith the additional parameter. (If an old entry point is called andencounters a PHV, it'll fall back to using the syntactic level,again possibly missing some valid optimization.)Back-patch to v12. The computation is surely also wrong before that,but it appears that we cannot reach a bad plan thanks to join orderrestrictions imposed on the subquery that the PlaceHolderVar came from.The error only became reachable when commit4be058f allowed trivialsubqueries to be collapsed out completely, eliminating their join orderrestrictions.Per report from Stephan Springl.Discussion:https://postgr.es/m/171041.1610849523@sss.pgh.pa.us1 parent920f853 commit55dc86e
File tree
25 files changed
+261
-131
lines changed- contrib/postgres_fdw
- src
- backend
- optimizer
- path
- plan
- prep
- util
- utils/adt
- include/optimizer
- test/regress
- expected
- sql
25 files changed
+261
-131
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5882 | 5882 |
| |
5883 | 5883 |
| |
5884 | 5884 |
| |
5885 |
| - | |
| 5885 | + | |
| 5886 | + | |
5886 | 5887 |
| |
5887 | 5888 |
| |
5888 | 5889 |
| |
|
Lines changed: 6 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
227 | 227 |
| |
228 | 228 |
| |
229 | 229 |
| |
230 |
| - | |
| 230 | + | |
231 | 231 |
| |
232 | 232 |
| |
233 | 233 |
| |
| |||
609 | 609 |
| |
610 | 610 |
| |
611 | 611 |
| |
612 |
| - | |
| 612 | + | |
613 | 613 |
| |
614 | 614 |
| |
615 | 615 |
| |
| |||
643 | 643 |
| |
644 | 644 |
| |
645 | 645 |
| |
646 |
| - | |
| 646 | + | |
647 | 647 |
| |
648 | 648 |
| |
649 | 649 |
| |
| |||
860 | 860 |
| |
861 | 861 |
| |
862 | 862 |
| |
863 |
| - | |
| 863 | + | |
864 | 864 |
| |
865 | 865 |
| |
866 | 866 |
| |
| |||
896 | 896 |
| |
897 | 897 |
| |
898 | 898 |
| |
899 |
| - | |
| 899 | + | |
900 | 900 |
| |
901 | 901 |
| |
902 | 902 |
| |
| |||
907 | 907 |
| |
908 | 908 |
| |
909 | 909 |
| |
910 |
| - | |
| 910 | + | |
911 | 911 |
| |
912 | 912 |
| |
913 | 913 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1858 | 1858 |
| |
1859 | 1859 |
| |
1860 | 1860 |
| |
1861 |
| - | |
| 1861 | + | |
1862 | 1862 |
| |
1863 | 1863 |
| |
1864 | 1864 |
| |
|
Lines changed: 11 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
196 | 196 |
| |
197 | 197 |
| |
198 | 198 |
| |
199 |
| - | |
| 199 | + | |
| 200 | + | |
200 | 201 |
| |
201 | 202 |
| |
202 | 203 |
| |
| |||
716 | 717 |
| |
717 | 718 |
| |
718 | 719 |
| |
719 |
| - | |
| 720 | + | |
720 | 721 |
| |
721 | 722 |
| |
722 | 723 |
| |
| |||
1696 | 1697 |
| |
1697 | 1698 |
| |
1698 | 1699 |
| |
1699 |
| - | |
| 1700 | + | |
| 1701 | + | |
1700 | 1702 |
| |
1701 | 1703 |
| |
1702 | 1704 |
| |
| |||
1996 | 1998 |
| |
1997 | 1999 |
| |
1998 | 2000 |
| |
1999 |
| - | |
| 2001 | + | |
| 2002 | + | |
2000 | 2003 |
| |
2001 | 2004 |
| |
2002 | 2005 |
| |
| |||
2141 | 2144 |
| |
2142 | 2145 |
| |
2143 | 2146 |
| |
2144 |
| - | |
| 2147 | + | |
| 2148 | + | |
2145 | 2149 |
| |
2146 | 2150 |
| |
2147 | 2151 |
| |
| |||
2156 | 2160 |
| |
2157 | 2161 |
| |
2158 | 2162 |
| |
2159 |
| - | |
| 2163 | + | |
| 2164 | + | |
2160 | 2165 |
| |
2161 | 2166 |
| |
2162 | 2167 |
| |
|
Lines changed: 37 additions & 24 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
153 | 153 |
| |
154 | 154 |
| |
155 | 155 |
| |
156 |
| - | |
| 156 | + | |
| 157 | + | |
157 | 158 |
| |
158 | 159 |
| |
159 | 160 |
| |
| |||
169 | 170 |
| |
170 | 171 |
| |
171 | 172 |
| |
172 |
| - | |
| 173 | + | |
| 174 | + | |
173 | 175 |
| |
174 | 176 |
| |
175 |
| - | |
| 177 | + | |
| 178 | + | |
176 | 179 |
| |
177 | 180 |
| |
178 |
| - | |
| 181 | + | |
| 182 | + | |
179 | 183 |
| |
180 | 184 |
| |
181 | 185 |
| |
| |||
2305 | 2309 |
| |
2306 | 2310 |
| |
2307 | 2311 |
| |
2308 |
| - | |
| 2312 | + | |
2309 | 2313 |
| |
2310 | 2314 |
| |
2311 | 2315 |
| |
| |||
2325 | 2329 |
| |
2326 | 2330 |
| |
2327 | 2331 |
| |
2328 |
| - | |
| 2332 | + | |
2329 | 2333 |
| |
2330 | 2334 |
| |
2331 | 2335 |
| |
2332 |
| - | |
| 2336 | + | |
2333 | 2337 |
| |
2334 | 2338 |
| |
2335 | 2339 |
| |
| |||
2368 | 2372 |
| |
2369 | 2373 |
| |
2370 | 2374 |
| |
2371 |
| - | |
| 2375 | + | |
| 2376 | + | |
2372 | 2377 |
| |
2373 | 2378 |
| |
2374 | 2379 |
| |
| |||
2438 | 2443 |
| |
2439 | 2444 |
| |
2440 | 2445 |
| |
2441 |
| - | |
| 2446 | + | |
2442 | 2447 |
| |
2443 | 2448 |
| |
2444 | 2449 |
| |
| |||
2663 | 2668 |
| |
2664 | 2669 |
| |
2665 | 2670 |
| |
2666 |
| - | |
| 2671 | + | |
| 2672 | + | |
2667 | 2673 |
| |
2668 | 2674 |
| |
2669 | 2675 |
| |
| |||
2684 | 2690 |
| |
2685 | 2691 |
| |
2686 | 2692 |
| |
2687 |
| - | |
| 2693 | + | |
| 2694 | + | |
2688 | 2695 |
| |
2689 | 2696 |
| |
2690 | 2697 |
| |
| |||
2703 | 2710 |
| |
2704 | 2711 |
| |
2705 | 2712 |
| |
2706 |
| - | |
| 2713 | + | |
2707 | 2714 |
| |
2708 | 2715 |
| |
2709 | 2716 |
| |
| |||
2751 | 2758 |
| |
2752 | 2759 |
| |
2753 | 2760 |
| |
2754 |
| - | |
| 2761 | + | |
| 2762 | + | |
2755 | 2763 |
| |
2756 | 2764 |
| |
2757 | 2765 |
| |
| |||
2796 | 2804 |
| |
2797 | 2805 |
| |
2798 | 2806 |
| |
2799 |
| - | |
| 2807 | + | |
2800 | 2808 |
| |
2801 | 2809 |
| |
2802 | 2810 |
| |
2803 | 2811 |
| |
2804 | 2812 |
| |
2805 | 2813 |
| |
2806 |
| - | |
| 2814 | + | |
2807 | 2815 |
| |
2808 | 2816 |
| |
2809 | 2817 |
| |
| |||
2822 | 2830 |
| |
2823 | 2831 |
| |
2824 | 2832 |
| |
2825 |
| - | |
| 2833 | + | |
| 2834 | + | |
2826 | 2835 |
| |
2827 | 2836 |
| |
2828 | 2837 |
| |
| |||
2856 | 2865 |
| |
2857 | 2866 |
| |
2858 | 2867 |
| |
2859 |
| - | |
| 2868 | + | |
| 2869 | + | |
2860 | 2870 |
| |
2861 | 2871 |
| |
2862 | 2872 |
| |
| |||
2926 | 2936 |
| |
2927 | 2937 |
| |
2928 | 2938 |
| |
2929 |
| - | |
| 2939 | + | |
2930 | 2940 |
| |
2931 | 2941 |
| |
2932 | 2942 |
| |
| |||
3036 | 3046 |
| |
3037 | 3047 |
| |
3038 | 3048 |
| |
3039 |
| - | |
| 3049 | + | |
| 3050 | + | |
3040 | 3051 |
| |
3041 | 3052 |
| |
3042 | 3053 |
| |
| |||
3050 | 3061 |
| |
3051 | 3062 |
| |
3052 | 3063 |
| |
3053 |
| - | |
| 3064 | + | |
3054 | 3065 |
| |
3055 | 3066 |
| |
3056 | 3067 |
| |
| |||
3667 | 3678 |
| |
3668 | 3679 |
| |
3669 | 3680 |
| |
3670 |
| - | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
3671 | 3684 |
| |
3672 | 3685 |
| |
3673 | 3686 |
| |
| |||
3689 | 3702 |
| |
3690 | 3703 |
| |
3691 | 3704 |
| |
3692 |
| - | |
| 3705 | + | |
3693 | 3706 |
| |
3694 | 3707 |
| |
3695 | 3708 |
| |
| |||
3801 | 3814 |
| |
3802 | 3815 |
| |
3803 | 3816 |
| |
3804 |
| - | |
| 3817 | + | |
3805 | 3818 |
| |
3806 | 3819 |
| |
3807 |
| - | |
| 3820 | + | |
3808 | 3821 |
| |
3809 | 3822 |
| |
3810 | 3823 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
598 | 598 |
| |
599 | 599 |
| |
600 | 600 |
| |
601 |
| - | |
| 601 | + | |
602 | 602 |
| |
603 | 603 |
| |
604 | 604 |
| |
|
0 commit comments
Comments
(0)