Further repair of eqjoinsel ndistinct-clamping logic.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 1 Sep 2011 04:18:28 +0000 (00:18 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 1 Sep 2011 04:19:38 +0000 (00:19 -0400)
commit0d3b231eebf41170f15605a943eb58e8d3d18374
treeef4d2a20c55a0f04c7fcfea67a0d7dd6d6690360
parent7971a57fd4ca4253393b77700d59670b5c6ec252
Further repair of eqjoinsel ndistinct-clamping logic.

Examination of examples provided by Mark Kirkwood and others has convinced
me that actually commit 7f3eba30c9d622d1981b1368f2d79ba0999cdff2 was quite
a few bricks shy of a load.  The useful part of that patch was clamping
ndistinct for the inner side of a semi or anti join, and the reason why
that's needed is that it's the only way that restriction clauses
eliminating rows from the inner relation can affect the estimated size of
the join result.  I had not clearly understood why the clamping was
appropriate, and so mis-extrapolated to conclude that we should clamp
ndistinct for the outer side too, as well as for both sides of regular
joins.  These latter actions were all wrong, and are reverted with this
patch.  In addition, the clamping logic is now made to affect the behavior
of both paths in eqjoinsel_semi, with or without MCV lists to compare.
When we have MCVs, we suppose that the most common values are the ones
that are most likely to survive the decimation resulting from a lower
restriction clause, so we think of the clamping as eliminating non-MCV
values, or potentially even the least-common MCVs for the inner relation.

Back-patch to 8.4, same as previous fixes in this area.
src/backend/utils/adt/selfuncs.c