]> granicus.if.org Git - postgresql/commit
Fix cost estimation for indexscan filter conditions.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 12 Apr 2012 00:24:17 +0000 (20:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 12 Apr 2012 00:24:17 +0000 (20:24 -0400)
commit732bfa2448c77bba5d98f485a387da77e1df8395
treed91af3a0d5d3a91ec0fb7a356bf4790b023db4af
parent880bfc3287dd68cfe90d10d9597d7b0fd2dae3e5
Fix cost estimation for indexscan filter conditions.

cost_index's method for estimating per-tuple costs of evaluating filter
conditions (a/k/a qpquals) was completely wrong in the presence of derived
indexable conditions, such as range conditions derived from a LIKE clause.
This was largely masked in common cases as a result of all simple operator
clauses having about the same costs, but it could show up in a big way when
dealing with functional indexes containing expensive functions, as seen for
example in bug #6579 from Istvan Endredy.  Rejigger the calculation to give
sane answers when the indexquals aren't a subset of the baserestrictinfo
list.  As a side benefit, we now do the calculation properly for cases
involving join clauses (ie, parameterized indexscans), which we always
overestimated before.

There are still cases where this is an oversimplification, such as clauses
that can be dropped because they are implied by a partial index's
predicate.  But we've never accounted for that in cost estimates before,
and I'm not convinced it's worth the cycles to try to do so.
src/backend/optimizer/path/costsize.c