forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita3179ab
committed
Recalculate where-needed data accurately after a join removal.
Up to now, remove_rel_from_query() has done a pretty shoddy jobof updating our where-needed bitmaps (per-Var attr_needed andper-PlaceHolderVar ph_needed relid sets). It removed direct mentionsof the to-be-removed baserel and outer join, which is the minimumamount of effort needed to keep the data structures self-consistent.But it didn't account for the fact that the removed join ON clauseprobably mentioned Vars of other relations, and those Vars might nownot be needed as high up in the join tree as before. It's easy toshow cases where this results in failing to remove a lower outer jointhat could also have been removed.To fix, recalculate the where-needed bitmaps from scratch aftereach successful join removal. This sounds expensive, but it seemsto add only negligible planner runtime. (We cheat a little bitby preserving "relation 0" entries in the bitmaps, allowing us toskip re-scanning the targetlist and HAVING qual.)The submitted test case drew attention because we had successfullyoptimized away the lower join prior to v16. I suspect that that'ssomewhat accidental and there are related cases that were neveroptimized before and now can be. I've not tried to come up withone, though.Perhaps we should back-patch this into v16 and v17 to repair theperformance regression. However, since it took a year for anyoneto notice the problem, it can't be affecting too many people. Let'slet the patch bake awhile in HEAD, and see if we get more complaints.Per bug #18627 from Mikaël Gourlaouen. No back-patch for now.Discussion:https://postgr.es/m/18627-44f950eb6a8416c2@postgresql.org1 parent7f7474a commita3179ab
File tree
9 files changed
+320
-37
lines changed- src
- backend/optimizer
- path
- plan
- util
- include/optimizer
- test/regress
- expected
- sql
9 files changed
+320
-37
lines changedLines changed: 40 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1293 | 1293 |
| |
1294 | 1294 |
| |
1295 | 1295 |
| |
1296 |
| - | |
| 1296 | + | |
| 1297 | + | |
1297 | 1298 |
| |
1298 | 1299 |
| |
1299 | 1300 |
| |
| |||
2422 | 2423 |
| |
2423 | 2424 |
| |
2424 | 2425 |
| |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
2425 | 2464 |
| |
2426 | 2465 |
| |
2427 | 2466 |
| |
|
Lines changed: 52 additions & 33 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
| 30 | + | |
30 | 31 |
| |
31 | 32 |
| |
32 | 33 |
| |
| |||
341 | 342 |
| |
342 | 343 |
| |
343 | 344 |
| |
344 |
| - | |
345 |
| - | |
346 |
| - | |
347 |
| - | |
348 |
| - | |
349 |
| - | |
350 |
| - | |
351 |
| - | |
352 |
| - | |
353 |
| - | |
354 |
| - | |
355 |
| - | |
356 |
| - | |
357 |
| - | |
358 |
| - | |
359 |
| - | |
360 |
| - | |
361 |
| - | |
362 |
| - | |
363 |
| - | |
364 |
| - | |
365 |
| - | |
366 |
| - | |
367 |
| - | |
368 |
| - | |
369 |
| - | |
370 |
| - | |
371 |
| - | |
372 |
| - | |
373 | 345 |
| |
374 | 346 |
| |
375 | 347 |
| |
| |||
450 | 422 |
| |
451 | 423 |
| |
452 | 424 |
| |
453 |
| - | |
454 |
| - | |
455 |
| - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
456 | 430 |
| |
457 | 431 |
| |
458 | 432 |
| |
| |||
540 | 514 |
| |
541 | 515 |
| |
542 | 516 |
| |
543 |
| - | |
| 517 | + | |
544 | 518 |
| |
545 | 519 |
| |
546 | 520 |
| |
547 | 521 |
| |
548 | 522 |
| |
549 | 523 |
| |
550 | 524 |
| |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
551 | 570 |
| |
552 | 571 |
| |
553 | 572 |
| |
|
Lines changed: 178 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
274 | 274 |
| |
275 | 275 |
| |
276 | 276 |
| |
| 277 | + | |
| 278 | + | |
277 | 279 |
| |
278 | 280 |
| |
279 | 281 |
| |
| |||
327 | 329 |
| |
328 | 330 |
| |
329 | 331 |
| |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
330 | 389 |
| |
331 | 390 |
| |
332 | 391 |
| |
| |||
488 | 547 |
| |
489 | 548 |
| |
490 | 549 |
| |
491 |
| - | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
492 | 554 |
| |
493 | 555 |
| |
494 | 556 |
| |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
495 | 598 |
| |
496 | 599 |
| |
497 | 600 |
| |
| |||
2445 | 2548 |
| |
2446 | 2549 |
| |
2447 | 2550 |
| |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
2448 | 2554 |
| |
2449 | 2555 |
| |
2450 | 2556 |
| |
| |||
3014 | 3120 |
| |
3015 | 3121 |
| |
3016 | 3122 |
| |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
3017 | 3128 |
| |
3018 | 3129 |
| |
3019 | 3130 |
| |
| |||
3155 | 3266 |
| |
3156 | 3267 |
| |
3157 | 3268 |
| |
| 3269 | + | |
| 3270 | + | |
| 3271 | + | |
| 3272 | + | |
| 3273 | + | |
| 3274 | + | |
| 3275 | + | |
| 3276 | + | |
| 3277 | + | |
| 3278 | + | |
| 3279 | + | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
| 3283 | + | |
| 3284 | + | |
| 3285 | + | |
| 3286 | + | |
| 3287 | + | |
| 3288 | + | |
| 3289 | + | |
| 3290 | + | |
| 3291 | + | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
| 3297 | + | |
| 3298 | + | |
| 3299 | + | |
| 3300 | + | |
| 3301 | + | |
| 3302 | + | |
| 3303 | + | |
| 3304 | + | |
| 3305 | + | |
| 3306 | + | |
| 3307 | + | |
| 3308 | + | |
| 3309 | + | |
| 3310 | + | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
| 3322 | + | |
| 3323 | + | |
| 3324 | + | |
| 3325 | + | |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
| 3331 | + | |
| 3332 | + | |
| 3333 | + | |
| 3334 | + | |
3158 | 3335 |
| |
3159 | 3336 |
| |
3160 | 3337 |
| |
|
0 commit comments
Comments
(0)