New version of the patch attached with the optimization to break the
loop before looking at all of the histogram values. I can reduce
join selectivity estimation runtime by reducing the values of the
left hand side or both of the sides, if there is interest.
> > Even if the above aspects of the code are really completely right, the
> > comments fail to explain why. I spent a lot of time on the comments,
> > but so far as these points are concerned they still only explain what
> > is being done and not why it's a useful calculation to make.
>
> I couldn't write better comments because I don't have strong arguments
> about it. We can say that we don't try to make use of the both of
> the endpoints, because we don't know how to combine them. We only use
> the one with matching family and masklen, and when both of them match
> we use the distant one to be on the safer side.
I added two more sentences to explain the calculation.