forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd0d4404
committed
Account for optimized MinMax aggregates during SS_finalize_plan.
We are capable of optimizing MIN() and MAX() aggregates on indexedcolumns into subqueries that exploit the index, rather than the normalthing of scanning the whole table. When we do this, we replace theAggref node(s) with Params referencing subquery outputs. Such Paramsreally ought to be included in the per-plan-node extParam/allParamsets computed by SS_finalize_plan. However, we've never done soup to now because of an ancient implementation choice to performthat substitution during set_plan_references, which runs afterSS_finalize_plan, so that SS_finalize_plan never sees these Params.This seems like clearly a bug, yet there have been no field reportsof problems that could trace to it. This may be because the typesof Plan nodes that could contain Aggrefs do not have any of therescan optimizations that are controlled by extParam/allParam.Nonetheless it seems certain to bite us someday, so let's fix itin a self-contained patch that can be back-patched if we find acase in which there's a live bug pre-v17.The cleanest fix would be to perform a separate tree walk to dothese substitutions before SS_finalize_plan runs. That seemsunattractive, first because a whole-tree mutation pass is expensive,and second because we lack infrastructure for visiting expressionsubtrees in a Plan tree, so that we'd need a new function knowingas much as SS_finalize_plan knows about that. I also consideredswapping the order of SS_finalize_plan and set_plan_references,but that fell foul of various assumptions that seem tricky to fix.So the approach adopted here is to teach SS_finalize_plan itselfto check for such Aggrefs. I refactored things a bit in setrefs.cto avoid having three copies of the code that does that.Given the lack of any currently-known bug, no test case here.Discussion:https://postgr.es/m/2391880.1689025003@sss.pgh.pa.us1 parentb8d3dae commitd0d4404
File tree
3 files changed
+66
-29
lines changed- src
- backend/optimizer/plan
- include/optimizer
3 files changed
+66
-29
lines changedLines changed: 42 additions & 26 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2181 | 2181 |
| |
2182 | 2182 |
| |
2183 | 2183 |
| |
| 2184 | + | |
2184 | 2185 |
| |
2185 | 2186 |
| |
2186 |
| - | |
2187 |
| - | |
| 2187 | + | |
| 2188 | + | |
2188 | 2189 |
| |
2189 |
| - | |
2190 |
| - | |
2191 |
| - | |
2192 |
| - | |
2193 |
| - | |
2194 |
| - | |
2195 |
| - | |
2196 |
| - | |
2197 |
| - | |
2198 |
| - | |
2199 |
| - | |
| 2190 | + | |
| 2191 | + | |
2200 | 2192 |
| |
2201 | 2193 |
| |
2202 | 2194 |
| |
| |||
3225 | 3217 |
| |
3226 | 3218 |
| |
3227 | 3219 |
| |
| 3220 | + | |
3228 | 3221 |
| |
3229 | 3222 |
| |
3230 |
| - | |
3231 |
| - | |
| 3223 | + | |
| 3224 | + | |
3232 | 3225 |
| |
3233 |
| - | |
3234 |
| - | |
3235 |
| - | |
3236 |
| - | |
3237 |
| - | |
3238 |
| - | |
3239 |
| - | |
3240 |
| - | |
3241 |
| - | |
3242 |
| - | |
3243 |
| - | |
| 3226 | + | |
| 3227 | + | |
3244 | 3228 |
| |
3245 | 3229 |
| |
3246 | 3230 |
| |
| |||
3395 | 3379 |
| |
3396 | 3380 |
| |
3397 | 3381 |
| |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
| 3393 | + | |
| 3394 | + | |
| 3395 | + | |
| 3396 | + | |
| 3397 | + | |
| 3398 | + | |
| 3399 | + | |
| 3400 | + | |
| 3401 | + | |
| 3402 | + | |
| 3403 | + | |
| 3404 | + | |
| 3405 | + | |
| 3406 | + | |
| 3407 | + | |
| 3408 | + | |
| 3409 | + | |
| 3410 | + | |
| 3411 | + | |
| 3412 | + | |
| 3413 | + | |
3398 | 3414 |
| |
3399 | 3415 |
| |
3400 | 3416 |
| |
|
Lines changed: 22 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2835 | 2835 |
| |
2836 | 2836 |
| |
2837 | 2837 |
| |
2838 |
| - | |
2839 |
| - | |
| 2838 | + | |
| 2839 | + | |
2840 | 2840 |
| |
2841 | 2841 |
| |
2842 | 2842 |
| |
| |||
2853 | 2853 |
| |
2854 | 2854 |
| |
2855 | 2855 |
| |
2856 |
| - | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
| 2863 | + | |
| 2864 | + | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
2857 | 2876 |
| |
2858 | 2877 |
| |
2859 | 2878 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
110 | 110 |
| |
111 | 111 |
| |
112 | 112 |
| |
| 113 | + | |
| 114 | + | |
113 | 115 |
| |
114 | 116 |
| |
115 | 117 |
| |
|
0 commit comments
Comments
(0)