forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitff4f889
committed
Fix bugs with degenerate window ORDER BY clauses in GROUPS/RANGE mode.
nodeWindowAgg.c failed to cope with the possibility that no orderingcolumns are defined in the window frame for GROUPS mode or RANGE OFFSETmode, leading to assertion failures or odd errors, as reported by MasahikoSawada and Lukas Eder. In RANGE OFFSET mode, an ordering column is reallyrequired, so add an Assert about that. In GROUPS mode, the code wouldwork, except that the node initialization code wasn't in sync with theexecution code about when to set up tuplestore read pointers and spareslots. Fix the latter for consistency's sake (even though I think thechanges described below make the out-of-sync cases unreachable for now).Per SQL spec, a single ordering column is required for RANGE OFFSET mode,and at least one ordering column is required for GROUPS mode. The parserenforced the former but not the latter; add a check for that.We were able to reach the no-ordering-column cases even with fully speccompliant queries, though, because the planner would drop partitioningand ordering columns from the generated plan if they were redundant withearlier columns according to the redundant-pathkey logic, for instance"PARTITION BY x ORDER BY y" in the presence of a "WHERE x=y" qual.While in principle that's an optimization that could save some pointlesscomparisons at runtime, it seems unlikely to be meaningful in the realworld. I think this behavior was not so much an intentional optimizationas a side-effect of an ancient decision to construct the plan node'sordering-column info by reverse-engineering the PathKeys of the inputpath. If we give up redundant-column removal then it takes very littlecode to generate the plan node info directly from the WindowClause,ensuring that we have the expected number of ordering columns in allcases. (If anyone does complain about this, the planner could perhapsbe taught to remove redundant columns only when it's safe to do so,ie *not* in RANGE OFFSET mode. But I doubt anyone ever will.)With these changes, the WindowAggPath.winpathkeys field is not used foranything anymore, so remove it.The test cases added here are not actually very interesting given theremoval of the redundant-column-removal logic, but they would representimportant corner cases if anyone ever tries to put that back.Tom Lane and Masahiko Sawada. Back-patch to v11 where RANGE OFFSETand GROUPS modes were added.Discussion:https://postgr.es/m/CAD21AoDrWqycq-w_+Bx1cjc+YUhZ11XTj9rfxNiNDojjBx8Fjw@mail.gmail.comDiscussion:https://postgr.es/m/153086788677.17476.8002640580496698831@wrigleys.postgresql.org1 parentedf59c4 commitff4f889
File tree
10 files changed
+217
-178
lines changed- src
- backend
- executor
- nodes
- optimizer
- plan
- util
- parser
- include
- nodes
- optimizer
- test/regress
- expected
- sql
10 files changed
+217
-178
lines changedLines changed: 30 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1079 | 1079 |
| |
1080 | 1080 |
| |
1081 | 1081 |
| |
| 1082 | + | |
1082 | 1083 |
| |
1083 | 1084 |
| |
1084 | 1085 |
| |
| |||
1143 | 1144 |
| |
1144 | 1145 |
| |
1145 | 1146 |
| |
1146 |
| - | |
1147 |
| - | |
| 1147 | + | |
| 1148 | + | |
1148 | 1149 |
| |
1149 | 1150 |
| |
1150 | 1151 |
| |
| |||
1182 | 1183 |
| |
1183 | 1184 |
| |
1184 | 1185 |
| |
1185 |
| - | |
| 1186 | + | |
1186 | 1187 |
| |
1187 | 1188 |
| |
1188 |
| - | |
1189 |
| - | |
| 1189 | + | |
| 1190 | + | |
1190 | 1191 |
| |
1191 | 1192 |
| |
1192 | 1193 |
| |
1193 |
| - | |
1194 |
| - | |
| 1194 | + | |
1195 | 1195 |
| |
1196 |
| - | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1197 | 1199 |
| |
1198 | 1200 |
| |
1199 |
| - | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
1200 | 1204 |
| |
1201 | 1205 |
| |
1202 | 1206 |
| |
| |||
1210 | 1214 |
| |
1211 | 1215 |
| |
1212 | 1216 |
| |
1213 |
| - | |
1214 |
| - | |
| 1217 | + | |
| 1218 | + | |
1215 | 1219 |
| |
1216 | 1220 |
| |
1217 | 1221 |
| |
| |||
1563 | 1567 |
| |
1564 | 1568 |
| |
1565 | 1569 |
| |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
1566 | 1573 |
| |
1567 | 1574 |
| |
1568 | 1575 |
| |
| |||
1814 | 1821 |
| |
1815 | 1822 |
| |
1816 | 1823 |
| |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
1817 | 1827 |
| |
1818 | 1828 |
| |
1819 | 1829 |
| |
| |||
2318 | 2328 |
| |
2319 | 2329 |
| |
2320 | 2330 |
| |
2321 |
| - | |
2322 |
| - | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
2323 | 2334 |
| |
2324 | 2335 |
| |
2325 | 2336 |
| |
2326 | 2337 |
| |
2327 | 2338 |
| |
2328 |
| - | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
2329 | 2342 |
| |
2330 |
| - | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2331 | 2346 |
| |
2332 | 2347 |
| |
2333 | 2348 |
| |
|
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2110 | 2110 |
| |
2111 | 2111 |
| |
2112 | 2112 |
| |
2113 |
| - | |
2114 | 2113 |
| |
2115 | 2114 |
| |
2116 | 2115 |
| |
|
Lines changed: 39 additions & 145 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
107 | 107 |
| |
108 | 108 |
| |
109 | 109 |
| |
110 |
| - | |
111 |
| - | |
112 |
| - | |
113 |
| - | |
114 |
| - | |
115 |
| - | |
116 |
| - | |
117 |
| - | |
118 |
| - | |
119 | 110 |
| |
120 | 111 |
| |
121 | 112 |
| |
| |||
2160 | 2151 |
| |
2161 | 2152 |
| |
2162 | 2153 |
| |
| 2154 | + | |
| 2155 | + | |
2163 | 2156 |
| |
2164 | 2157 |
| |
2165 |
| - | |
2166 |
| - | |
2167 |
| - | |
2168 |
| - | |
2169 |
| - | |
2170 | 2158 |
| |
2171 | 2159 |
| |
2172 | 2160 |
| |
2173 | 2161 |
| |
2174 | 2162 |
| |
2175 | 2163 |
| |
| 2164 | + | |
2176 | 2165 |
| |
2177 | 2166 |
| |
2178 | 2167 |
| |
| |||
2183 | 2172 |
| |
2184 | 2173 |
| |
2185 | 2174 |
| |
2186 |
| - | |
2187 |
| - | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
2188 | 2182 |
| |
2189 |
| - | |
2190 |
| - | |
2191 |
| - | |
2192 |
| - | |
2193 |
| - | |
2194 |
| - | |
2195 |
| - | |
2196 |
| - | |
2197 |
| - | |
2198 |
| - | |
2199 |
| - | |
2200 |
| - | |
2201 |
| - | |
2202 |
| - | |
2203 |
| - | |
2204 |
| - | |
2205 |
| - | |
2206 |
| - | |
2207 |
| - | |
2208 |
| - | |
2209 |
| - | |
2210 |
| - | |
2211 |
| - | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
2212 | 2212 |
| |
2213 | 2213 |
| |
2214 | 2214 |
| |
| |||
2234 | 2234 |
| |
2235 | 2235 |
| |
2236 | 2236 |
| |
2237 |
| - | |
2238 |
| - | |
2239 |
| - | |
2240 |
| - | |
2241 |
| - | |
2242 |
| - | |
2243 |
| - | |
2244 |
| - | |
2245 |
| - | |
2246 |
| - | |
2247 |
| - | |
2248 |
| - | |
2249 |
| - | |
2250 |
| - | |
2251 |
| - | |
2252 |
| - | |
2253 |
| - | |
2254 |
| - | |
2255 |
| - | |
2256 |
| - | |
2257 |
| - | |
2258 |
| - | |
2259 |
| - | |
2260 |
| - | |
2261 |
| - | |
2262 |
| - | |
2263 |
| - | |
2264 |
| - | |
2265 |
| - | |
2266 |
| - | |
2267 |
| - | |
2268 |
| - | |
2269 |
| - | |
2270 |
| - | |
2271 |
| - | |
2272 |
| - | |
2273 |
| - | |
2274 |
| - | |
2275 |
| - | |
2276 |
| - | |
2277 |
| - | |
2278 |
| - | |
2279 |
| - | |
2280 |
| - | |
2281 |
| - | |
2282 |
| - | |
2283 |
| - | |
2284 |
| - | |
2285 |
| - | |
2286 |
| - | |
2287 |
| - | |
2288 |
| - | |
2289 |
| - | |
2290 |
| - | |
2291 |
| - | |
2292 |
| - | |
2293 |
| - | |
2294 |
| - | |
2295 |
| - | |
2296 |
| - | |
2297 |
| - | |
2298 |
| - | |
2299 |
| - | |
2300 |
| - | |
2301 |
| - | |
2302 |
| - | |
2303 |
| - | |
2304 |
| - | |
2305 |
| - | |
2306 |
| - | |
2307 |
| - | |
2308 |
| - | |
2309 |
| - | |
2310 |
| - | |
2311 |
| - | |
2312 |
| - | |
2313 |
| - | |
2314 |
| - | |
2315 |
| - | |
2316 |
| - | |
2317 |
| - | |
2318 |
| - | |
2319 |
| - | |
2320 |
| - | |
2321 |
| - | |
2322 |
| - | |
2323 |
| - | |
2324 |
| - | |
2325 |
| - | |
2326 |
| - | |
2327 |
| - | |
2328 |
| - | |
2329 |
| - | |
2330 |
| - | |
2331 |
| - | |
2332 |
| - | |
2333 |
| - | |
2334 |
| - | |
2335 |
| - | |
2336 |
| - | |
2337 |
| - | |
2338 |
| - | |
2339 |
| - | |
2340 |
| - | |
2341 |
| - | |
2342 |
| - | |
2343 | 2237 |
| |
2344 | 2238 |
| |
2345 | 2239 |
| |
|
Lines changed: 1 addition & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4603 | 4603 |
| |
4604 | 4604 |
| |
4605 | 4605 |
| |
4606 |
| - | |
4607 |
| - | |
| 4606 | + | |
4608 | 4607 |
| |
4609 | 4608 |
| |
4610 | 4609 |
| |
| |||
5465 | 5464 |
| |
5466 | 5465 |
| |
5467 | 5466 |
| |
5468 |
| - | |
5469 |
| - | |
5470 | 5467 |
| |
5471 | 5468 |
| |
5472 | 5469 |
| |
|
Lines changed: 3 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3072 | 3072 |
| |
3073 | 3073 |
| |
3074 | 3074 |
| |
3075 |
| - | |
3076 | 3075 |
| |
3077 |
| - | |
3078 |
| - | |
| 3076 | + | |
| 3077 | + | |
3079 | 3078 |
| |
3080 | 3079 |
| |
3081 | 3080 |
| |
3082 | 3081 |
| |
3083 | 3082 |
| |
3084 | 3083 |
| |
3085 | 3084 |
| |
3086 |
| - | |
3087 |
| - | |
| 3085 | + | |
3088 | 3086 |
| |
3089 | 3087 |
| |
3090 | 3088 |
| |
| |||
3102 | 3100 |
| |
3103 | 3101 |
| |
3104 | 3102 |
| |
3105 |
| - | |
3106 | 3103 |
| |
3107 | 3104 |
| |
3108 | 3105 |
| |
|
0 commit comments
Comments
(0)