]> granicus.if.org Git - postgresql/commit
Clamp indexscan filter condition cost estimate to be not less than zero.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 12 Apr 2012 00:24:39 +0000 (20:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 12 Apr 2012 00:24:39 +0000 (20:24 -0400)
commit8d444c90d87115934874d07e61f1c080b282aa6e
tree579f9d4ff3ea7bc2edd671e311bfb332649cff08
parent8555586707dbf5f731f015691a87cc0ab53efcca
Clamp indexscan filter condition cost estimate to be not less than zero.

cost_index tries to estimate the per-tuple costs of evaluating filter
conditions (a/k/a qpquals) by subtracting the estimated cost of the
indexqual conditions from that of the baserestrictinfo conditions.  This is
correct so long as the indexquals list is a subset of the baserestrictinfo
list.  However, in the presence of derived indexable conditions it's
completely wrong, leading to bogus or even negative scan cost estimates,
as seen for example in bug #6579 from Istvan Endredy.  In practice the
problem isn't severe except in the specific case of a LIKE optimization on
a functional index containing a very expensive function.

A proper fix for this might change cost estimates by more than people would
like for stable branches, so in the back branches let's just clamp the cost
difference to be not less than zero.  That will at least prevent completely
insane behavior, while not changing the results normally.
src/backend/optimizer/path/costsize.c