forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitc40ba5f
committed
Fix rowcount estimate for SubqueryScan that's under a Gather.
SubqueryScan was always getting labeled with a rowcount estimateappropriate for non-parallel cases. However, nodes that areunderneath a Gather should be treated as processing only oneworker's share of the rows, whether the particular node is explicitlyparallel-aware or not. Most non-scan-level node types get thisright automatically because they base their rowcount estimate onthat of their input sub-Path(s). But SubqueryScan didn't do that,instead using the whole-relation rowcount estimate as if it werea non-parallel-aware scan node. If there is a parallel-aware nodebelow the SubqueryScan, this is wrong, and it results in inflatingthe cost estimates for nodes above the SubqueryScan, which can causeus to not choose a parallel plan, or choose a silly one --- as indeedis visible in the one regression test whose results change with thispatch. (Although that plan tree appears to contain no SubqueryScans,there were some in it before setrefs.c deleted them.)To fix, use path->subpath->rows not baserel->tuples as the numberof input tuples we'll process. This requires estimating the quals'selectivity afresh, which is slightly annoying; but it shouldn'treally add much cost thanks to the caching done in RestrictInfo.This is pretty clearly a bug fix, but I'll refrain from back-patchingas people might not appreciate plan choices changing in stable branches.The fact that it took us this long to identify the bug suggests thatit's not a major problem.Per report from bucoo, though this is not his proposed patch.Discussion:https://postgr.es/m/202204121457159307248@sohu.com1 parentdc2be6e commitc40ba5f
File tree
2 files changed
+22
-10
lines changed- src
- backend/optimizer/path
- test/regress/expected
2 files changed
+22
-10
lines changedLines changed: 18 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1395 | 1395 |
| |
1396 | 1396 |
| |
1397 | 1397 |
| |
| 1398 | + | |
1398 | 1399 |
| |
1399 | 1400 |
| |
1400 | 1401 |
| |
1401 | 1402 |
| |
1402 | 1403 |
| |
1403 | 1404 |
| |
1404 | 1405 |
| |
1405 |
| - | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
1406 | 1412 |
| |
1407 |
| - | |
| 1413 | + | |
| 1414 | + | |
1408 | 1415 |
| |
1409 |
| - | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
1410 | 1424 |
| |
1411 | 1425 |
| |
1412 | 1426 |
| |
| |||
1421 | 1435 |
| |
1422 | 1436 |
| |
1423 | 1437 |
| |
1424 |
| - | |
| 1438 | + | |
1425 | 1439 |
| |
1426 | 1440 |
| |
1427 | 1441 |
| |
|
Lines changed: 4 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1487 | 1487 |
| |
1488 | 1488 |
| |
1489 | 1489 |
| |
1490 |
| - | |
1491 |
| - | |
1492 |
| - | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
1493 | 1493 |
| |
1494 |
| - | |
1495 |
| - | |
1496 | 1494 |
| |
1497 |
| - | |
| 1495 | + | |
1498 | 1496 |
| |
1499 | 1497 |
| |
1500 | 1498 |
| |
|
0 commit comments
Comments
(0)