forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd8e6b84
committed
Avoid regressions in foreign-key-based selectivity estimates.
David Rowley found that the "use the smallest per-column selectivity"heuristic applied in some cases by get_foreign_key_join_selectivity()was badly off if the FK columns are independent, producing estimatesmuch worse than we got before that code was added in 9.6.One case where that heuristic was used was for LEFT and FULL outer joinswith the referenced rel on the outside of the join. But we should notreally need to special-case those here. eqjoinsel() never has had such aspecial case; the correction is applied by calc_joinrel_size_estimate()instead. Let's just estimate such cases like inner joins and rely on thatlater adjustment. (I think there was something of a thinko here, in thatthe comments seem to be thinking about the selectivity as defined forsemi/anti joins; but that shouldn't apply to left/full joins.) Add aregression test exercising such a case to show that this is sane inat least some cases.The other case where we used that heuristic was for SEMI/ANTI outer joins,either if the referenced rel was on the outside, or if it was on the insidebut was part of a join within the RHS. In either case, the FK doesn't giveus a lot of traction towards estimating the selectivity. To ensure thatwe don't have regressions from what happened before 9.6, let's punt byignoring the FK in such cases and applying the traditional selectivitycalculation. (We might be able to improve on that later, but for nowI just want to be sure it's not worse than 9.5.)Report and patch by David Rowley, simplified a bit by me. Back-patchto 9.6 where this code was added.Discussion:https://postgr.es/m/CAKJS1f8NO8oCDcxrteohG6O72uU1saEVT9qX=R8pENr5QWerXw@mail.gmail.com1 parentbd61d5a commitd8e6b84
File tree
3 files changed
+93
-67
lines changed- src
- backend/optimizer/path
- test/regress
- expected
- sql
3 files changed
+93
-67
lines changedLines changed: 30 additions & 67 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4318 | 4318 |
| |
4319 | 4319 |
| |
4320 | 4320 |
| |
4321 |
| - | |
4322 | 4321 |
| |
4323 | 4322 |
| |
4324 | 4323 |
| |
| |||
4337 | 4336 |
| |
4338 | 4337 |
| |
4339 | 4338 |
| |
| 4339 | + | |
| 4340 | + | |
| 4341 | + | |
| 4342 | + | |
| 4343 | + | |
| 4344 | + | |
| 4345 | + | |
| 4346 | + | |
| 4347 | + | |
| 4348 | + | |
| 4349 | + | |
| 4350 | + | |
| 4351 | + | |
| 4352 | + | |
| 4353 | + | |
| 4354 | + | |
4340 | 4355 |
| |
4341 | 4356 |
| |
4342 | 4357 |
| |
| |||
4437 | 4452 |
| |
4438 | 4453 |
| |
4439 | 4454 |
| |
4440 |
| - | |
4441 |
| - | |
4442 |
| - | |
4443 |
| - | |
| 4455 | + | |
4444 | 4456 |
| |
4445 | 4457 |
| |
4446 | 4458 |
| |
| |||
4453 | 4465 |
| |
4454 | 4466 |
| |
4455 | 4467 |
| |
4456 |
| - | |
| 4468 | + | |
4457 | 4469 |
| |
4458 | 4470 |
| |
4459 |
| - | |
4460 |
| - | |
4461 |
| - | |
4462 |
| - | |
4463 |
| - | |
4464 |
| - | |
4465 |
| - | |
| 4471 | + | |
| 4472 | + | |
| 4473 | + | |
| 4474 | + | |
| 4475 | + | |
| 4476 | + | |
| 4477 | + | |
| 4478 | + | |
| 4479 | + | |
4466 | 4480 |
| |
4467 |
| - | |
4468 |
| - | |
4469 |
| - | |
4470 |
| - | |
4471 |
| - | |
4472 |
| - | |
4473 |
| - | |
4474 |
| - | |
4475 |
| - | |
4476 |
| - | |
4477 |
| - | |
4478 |
| - | |
4479 |
| - | |
4480 |
| - | |
4481 |
| - | |
4482 |
| - | |
4483 |
| - | |
4484 |
| - | |
4485 |
| - | |
4486 |
| - | |
4487 |
| - | |
| 4481 | + | |
| 4482 | + | |
4488 | 4483 |
| |
4489 |
| - | |
4490 |
| - | |
4491 |
| - | |
4492 |
| - | |
4493 |
| - | |
4494 |
| - | |
4495 |
| - | |
4496 |
| - | |
4497 |
| - | |
4498 |
| - | |
4499 |
| - | |
4500 |
| - | |
4501 |
| - | |
| 4484 | + | |
4502 | 4485 |
| |
4503 | 4486 |
| |
4504 | 4487 |
| |
| |||
4512 | 4495 |
| |
4513 | 4496 |
| |
4514 | 4497 |
| |
4515 |
| - | |
4516 |
| - | |
4517 |
| - | |
4518 |
| - | |
4519 |
| - | |
4520 |
| - | |
4521 |
| - | |
4522 |
| - | |
4523 |
| - | |
4524 |
| - | |
4525 |
| - | |
4526 |
| - | |
4527 |
| - | |
4528 |
| - | |
4529 |
| - | |
4530 |
| - | |
4531 |
| - | |
4532 |
| - | |
4533 |
| - | |
4534 |
| - | |
4535 | 4498 |
| |
4536 | 4499 |
| |
4537 | 4500 |
| |
|
Lines changed: 35 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5328 | 5328 |
| |
5329 | 5329 |
| |
5330 | 5330 |
| |
| 5331 | + | |
| 5332 | + | |
| 5333 | + | |
| 5334 | + | |
| 5335 | + | |
| 5336 | + | |
| 5337 | + | |
| 5338 | + | |
| 5339 | + | |
| 5340 | + | |
| 5341 | + | |
| 5342 | + | |
| 5343 | + | |
| 5344 | + | |
| 5345 | + | |
| 5346 | + | |
| 5347 | + | |
| 5348 | + | |
| 5349 | + | |
| 5350 | + | |
| 5351 | + | |
| 5352 | + | |
| 5353 | + | |
| 5354 | + | |
| 5355 | + | |
| 5356 | + | |
| 5357 | + | |
| 5358 | + | |
| 5359 | + | |
| 5360 | + | |
| 5361 | + | |
| 5362 | + | |
| 5363 | + | |
| 5364 | + | |
| 5365 | + | |
5331 | 5366 |
| |
5332 | 5367 |
| |
5333 | 5368 |
| |
|
Lines changed: 28 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1733 | 1733 |
| |
1734 | 1734 |
| |
1735 | 1735 |
| |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
1736 | 1764 |
| |
1737 | 1765 |
| |
1738 | 1766 |
| |
|
0 commit comments
Comments
(0)