- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit7ad6960
committed
Still more fixes for planner's handling of LATERAL references.
More fuzz testing by Andreas Seltenreich exposed that the planner did notcope well with chains of lateral references. If relation X references Ylaterally, and Y references Z laterally, then we will have to scan X on theinside of a nestloop with Z, so for all intents and purposes X is laterallydependent on Z too. The planner did not understand this and would generateintermediate joins that could not be used. While that was usually harmlessexcept for wasting some planning cycles, under the right circumstances itwould lead to "failed to build any N-way joins" or "could not devise aquery plan" planner failures.To fix that, convert the existing per-relation lateral_relids andlateral_referencers relid sets into their transitive closures; that is,they now show all relations on which a rel is directly or indirectlylaterally dependent. This not only fixes the chained-reference problembut allows some of the relevant tests to be made substantially simplerand faster, since they can be reduced to simple bitmap manipulationsinstead of searches of the LateralJoinInfo list.Also, when a PlaceHolderVar that is due to be evaluated at a join containslateral references, we should treat those references as indirect lateraldependencies of each of the join's base relations. This prevents us fromtrying to join any individual base relations to the lateral referencesource before the join is formed, which again cannot work.Andreas' testing also exposed another oversight in the "dangerousPlaceHolderVar" test added in commit85e5e22. Simply rejectingunsafe join paths in joinpath.c is insufficient, because in some caseswe will end up rejecting *all* possible paths for a particular join, againleading to "could not devise a query plan" failures. The restriction hasto be known also to join_is_legal and its cohort functions, so that theywill not select a join for which that will happen. I chose to move thesupporting logic into joinrels.c where the latter functions are.Back-patch to 9.3 where LATERAL support was introduced.1 parentc6a67bb commit7ad6960
File tree
9 files changed
+531
-188
lines changed- src
- backend/optimizer
- path
- plan
- util
- include
- nodes
- optimizer
- test/regress
- expected
- sql
9 files changed
+531
-188
lines changedLines changed: 6 additions & 73 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
247 | 247 |
| |
248 | 248 |
| |
249 | 249 |
| |
250 |
| - | |
251 |
| - | |
252 |
| - | |
253 |
| - | |
254 |
| - | |
255 |
| - | |
256 |
| - | |
257 |
| - | |
258 |
| - | |
259 |
| - | |
260 |
| - | |
261 |
| - | |
262 |
| - | |
263 |
| - | |
264 |
| - | |
265 |
| - | |
266 |
| - | |
267 |
| - | |
268 |
| - | |
269 |
| - | |
270 |
| - | |
271 |
| - | |
272 |
| - | |
273 |
| - | |
274 |
| - | |
275 |
| - | |
276 |
| - | |
277 |
| - | |
278 |
| - | |
279 |
| - | |
280 |
| - | |
281 |
| - | |
282 |
| - | |
283 |
| - | |
284 |
| - | |
285 |
| - | |
286 |
| - | |
287 |
| - | |
288 |
| - | |
289 |
| - | |
290 |
| - | |
291 |
| - | |
292 |
| - | |
293 |
| - | |
294 |
| - | |
295 |
| - | |
296 |
| - | |
297 |
| - | |
298 | 250 |
| |
299 | 251 |
| |
300 | 252 |
| |
| |||
318 | 270 |
| |
319 | 271 |
| |
320 | 272 |
| |
321 |
| - | |
322 |
| - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
323 | 276 |
| |
324 | 277 |
| |
325 | 278 |
| |
326 | 279 |
| |
327 | 280 |
| |
328 | 281 |
| |
329 |
| - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
330 | 285 |
| |
331 | 286 |
| |
332 | 287 |
| |
333 | 288 |
| |
334 | 289 |
| |
335 | 290 |
| |
336 |
| - | |
337 |
| - | |
338 |
| - | |
339 |
| - | |
340 |
| - | |
341 |
| - | |
342 |
| - | |
343 |
| - | |
344 |
| - | |
345 |
| - | |
346 | 291 |
| |
347 | 292 |
| |
348 | 293 |
| |
| |||
416 | 361 |
| |
417 | 362 |
| |
418 | 363 |
| |
419 |
| - | |
420 |
| - | |
421 |
| - | |
422 |
| - | |
423 |
| - | |
424 |
| - | |
425 | 364 |
| |
426 | 365 |
| |
427 | 366 |
| |
| |||
501 | 440 |
| |
502 | 441 |
| |
503 | 442 |
| |
504 |
| - | |
505 |
| - | |
506 |
| - | |
507 |
| - | |
508 |
| - | |
509 |
| - | |
510 | 443 |
| |
511 | 444 |
| |
512 | 445 |
| |
|
0 commit comments
Comments
(0)