- Notifications
You must be signed in to change notification settings - Fork28
Commitd364e88
committed
Fix ancient thinko in mergejoin cost estimation.
"rescanratio" was computed as 1 + rescanned-tuples / total-inner-tuples,which is sensible if it's to be multiplied by total-inner-tuples or a costvalue corresponding to scanning all the inner tuples. But in reality itwas (mostly) multiplied by inner_rows or a related cost, numbers that takeinto account the possibility of stopping short of scanning the whole innerrelation thanks to a limited key range in the outer relation. This'dstill make sense if we could expect that stopping short would result in aproportional decrease in the number of tuples that have to be rescanned.It does not, however. The argument that establishes the validity of ourestimate for that number is independent of whether we scan all of the innerrelation or stop short, and experimentation also shows that stopping shortdoesn't reduce the number of rescanned tuples. So the correct calculationis 1 + rescanned-tuples / inner_rows, and we should be sure to multiplythat by inner_rows or a corresponding cost value.Most of the time this doesn't make much difference, but if we haveboth a high rescan rate (due to lots of duplicate values) and an outerkey range much smaller than the inner key range, then the error canbe significant, leading to a large underestimate of the cost associatedwith rescanning.Per report from Vijaykumar Jain. This thinko appears to go all the wayback to the introduction of the rescan estimation logic in commit70fba70, so back-patch to all supported branches.Discussion:https://postgr.es/m/CAE7uO5hMb_TZYJcZmLAgO6iD68AkEK6qCe7i=vZUkCpoKns+EQ@mail.gmail.com1 parentf94cec6 commitd364e88
1 file changed
+8
-3
lines changedLines changed: 8 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2941 | 2941 |
| |
2942 | 2942 |
| |
2943 | 2943 |
| |
2944 |
| - | |
2945 |
| - | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
2946 | 2951 |
| |
2947 | 2952 |
| |
2948 | 2953 |
| |
| |||
2969 | 2974 |
| |
2970 | 2975 |
| |
2971 | 2976 |
| |
2972 |
| - | |
| 2977 | + | |
2973 | 2978 |
| |
2974 | 2979 |
| |
2975 | 2980 |
| |
|
0 commit comments
Comments
(0)