forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit4ac385a
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.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.Back-patch of v17 commitsd0d4404 and779ac2c. Whend0d4404went in, there was no evidence that it was fixing a reachable bug,so I refrained from back-patching. Now we have such evidence.Per bug #18465 from Hal Takahara. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/18465-2fae927718976b22@postgresql.orgDiscussion:https://postgr.es/m/2391880.1689025003@sss.pgh.pa.us1 parent484b958 commit4ac385a
File tree
5 files changed
+107
-29
lines changed- src
- backend/optimizer/plan
- include/optimizer
- test/regress
- expected
- sql
5 files changed
+107
-29
lines changedLines changed: 42 additions & 26 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2088 | 2088 |
| |
2089 | 2089 |
| |
2090 | 2090 |
| |
| 2091 | + | |
2091 | 2092 |
| |
2092 | 2093 |
| |
2093 |
| - | |
2094 |
| - | |
| 2094 | + | |
| 2095 | + | |
2095 | 2096 |
| |
2096 |
| - | |
2097 |
| - | |
2098 |
| - | |
2099 |
| - | |
2100 |
| - | |
2101 |
| - | |
2102 |
| - | |
2103 |
| - | |
2104 |
| - | |
2105 |
| - | |
2106 |
| - | |
| 2097 | + | |
| 2098 | + | |
2107 | 2099 |
| |
2108 | 2100 |
| |
2109 | 2101 |
| |
| |||
3030 | 3022 |
| |
3031 | 3023 |
| |
3032 | 3024 |
| |
| 3025 | + | |
3033 | 3026 |
| |
3034 | 3027 |
| |
3035 |
| - | |
3036 |
| - | |
| 3028 | + | |
| 3029 | + | |
3037 | 3030 |
| |
3038 |
| - | |
3039 |
| - | |
3040 |
| - | |
3041 |
| - | |
3042 |
| - | |
3043 |
| - | |
3044 |
| - | |
3045 |
| - | |
3046 |
| - | |
3047 |
| - | |
3048 |
| - | |
| 3031 | + | |
| 3032 | + | |
3049 | 3033 |
| |
3050 | 3034 |
| |
3051 | 3035 |
| |
| |||
3199 | 3183 |
| |
3200 | 3184 |
| |
3201 | 3185 |
| |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
| 3213 | + | |
| 3214 | + | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
3202 | 3218 |
| |
3203 | 3219 |
| |
3204 | 3220 |
| |
|
Lines changed: 22 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2849 | 2849 |
| |
2850 | 2850 |
| |
2851 | 2851 |
| |
2852 |
| - | |
2853 |
| - | |
| 2852 | + | |
| 2853 | + | |
2854 | 2854 |
| |
2855 | 2855 |
| |
2856 | 2856 |
| |
| |||
2867 | 2867 |
| |
2868 | 2868 |
| |
2869 | 2869 |
| |
2870 |
| - | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
2871 | 2890 |
| |
2872 | 2891 |
| |
2873 | 2892 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
113 | 113 |
| |
114 | 114 |
| |
115 | 115 |
| |
| 116 | + | |
| 117 | + | |
116 | 118 |
| |
117 | 119 |
| |
118 | 120 |
| |
|
Lines changed: 31 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1249 | 1249 |
| |
1250 | 1250 |
| |
1251 | 1251 |
| |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
1252 | 1283 |
| |
1253 | 1284 |
| |
1254 | 1285 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
431 | 431 |
| |
432 | 432 |
| |
433 | 433 |
| |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
434 | 444 |
| |
435 | 445 |
| |
436 | 446 |
| |
|
0 commit comments
Comments
(0)