forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit2388658
committed
Fix old corner-case logic error in final_cost_nestloop().
When costing a nestloop with stop-at-first-inner-match semantics, and anon-indexscan inner path, final_cost_nestloop() wants to charge the fullscan cost of the inner rel at least once, with additional scans chargedat inner_rescan_run_cost which might be less. However the logic fordoing this effectively assumed that outer_matched_rows is at least 1.If it's zero, which is not unlikely for a small outer rel, we ended upcharging inner_run_cost plus N times inner_rescan_run_cost, as much asdouble the correct charge for an outer rel with only one row thatwe're betting won't be matched. (Unless the inner rel is materialized,in which case it has very small inner_rescan_run_cost and the costis not so far off what it should have been.)The upshot of this was that the planner had a tendency to select plansthat failed to make effective use of the stop-at-first-inner-matchsemantics, and that might have Materialize nodes in them even when thepredicted number of executions of the Materialize subplan was only 1.This was not so obvious before commit9c7f522, because the case onlyarose in connection with semi/anti joins where there's not freedom toreverse the join order. But with the addition of unique-inner joins,it could result in some fairly bad planning choices, as reported byTeodor Sigaev. Indeed, some of the test cases added by that commithave plans that look dubious on closer inspection, and are changedby this patch.Fix the logic to ensure that we don't charge for too many inner scans.I chose to adjust it so that the full-freight scan cost is associatedwith an unmatched outer row if possible, not a matched one, since thatseems like a better model of what would happen at runtime.This is a longstanding bug, but given the lesser impact in back branches,and the lack of field complaints, I won't risk a back-patch.Discussion:https://postgr.es/m/CAKJS1f-LzkUsFxdJ_-Luy38orQ+AdEXM5o+vANR+-pHAWPSecg@mail.gmail.com1 parent66b84fa commit2388658
File tree
2 files changed
+42
-38
lines changed- src
- backend/optimizer/path
- test/regress/expected
2 files changed
+42
-38
lines changedLines changed: 20 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2214 | 2214 |
| |
2215 | 2215 |
| |
2216 | 2216 |
| |
| 2217 | + | |
2217 | 2218 |
| |
2218 | 2219 |
| |
2219 | 2220 |
| |
| |||
2226 | 2227 |
| |
2227 | 2228 |
| |
2228 | 2229 |
| |
| 2230 | + | |
2229 | 2231 |
| |
2230 | 2232 |
| |
2231 | 2233 |
| |
| |||
2269 | 2271 |
| |
2270 | 2272 |
| |
2271 | 2273 |
| |
2272 |
| - | |
| 2274 | + | |
2273 | 2275 |
| |
2274 | 2276 |
| |
2275 | 2277 |
| |
| |||
2287 | 2289 |
| |
2288 | 2290 |
| |
2289 | 2291 |
| |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
2290 | 2295 |
| |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
2291 | 2301 |
| |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
2292 | 2306 |
| |
2293 | 2307 |
| |
2294 |
| - | |
2295 |
| - | |
2296 |
| - | |
2297 |
| - | |
2298 |
| - | |
2299 |
| - | |
| 2308 | + | |
| 2309 | + | |
2300 | 2310 |
| |
2301 |
| - | |
2302 |
| - | |
2303 |
| - | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
2304 | 2314 |
| |
2305 | 2315 |
| |
2306 | 2316 |
| |
|
Lines changed: 22 additions & 28 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5476 | 5476 |
| |
5477 | 5477 |
| |
5478 | 5478 |
| |
5479 |
| - | |
5480 |
| - | |
| 5479 | + | |
| 5480 | + | |
5481 | 5481 |
| |
5482 | 5482 |
| |
5483 | 5483 |
| |
5484 | 5484 |
| |
5485 |
| - | |
5486 |
| - | |
5487 |
| - | |
| 5485 | + | |
5488 | 5486 |
| |
5489 |
| - | |
| 5487 | + | |
5490 | 5488 |
| |
5491 |
| - | |
| 5489 | + | |
| 5490 | + | |
5492 | 5491 |
| |
5493 |
| - | |
5494 |
| - | |
5495 |
| - | |
5496 |
| - | |
| 5492 | + | |
| 5493 | + | |
| 5494 | + | |
5497 | 5495 |
| |
5498 | 5496 |
| |
5499 | 5497 |
| |
5500 | 5498 |
| |
5501 | 5499 |
| |
5502 |
| - | |
5503 |
| - | |
| 5500 | + | |
| 5501 | + | |
5504 | 5502 |
| |
5505 | 5503 |
| |
5506 | 5504 |
| |
5507 | 5505 |
| |
5508 |
| - | |
5509 |
| - | |
5510 |
| - | |
| 5506 | + | |
5511 | 5507 |
| |
5512 |
| - | |
| 5508 | + | |
| 5509 | + | |
5513 | 5510 |
| |
5514 |
| - | |
5515 |
| - | |
| 5511 | + | |
| 5512 | + | |
5516 | 5513 |
| |
5517 |
| - | |
5518 |
| - | |
5519 |
| - | |
5520 |
| - | |
| 5514 | + | |
| 5515 | + | |
| 5516 | + | |
5521 | 5517 |
| |
5522 | 5518 |
| |
5523 | 5519 |
| |
| |||
5558 | 5554 |
| |
5559 | 5555 |
| |
5560 | 5556 |
| |
| 5557 | + | |
| 5558 | + | |
5561 | 5559 |
| |
5562 | 5560 |
| |
5563 |
| - | |
5564 |
| - | |
5565 |
| - | |
5566 |
| - | |
5567 |
| - | |
| 5561 | + | |
5568 | 5562 |
| |
5569 | 5563 |
| |
5570 | 5564 |
| |
|
0 commit comments
Comments
(0)