OSDN Git Service

Fix some problems with selectivity estimation for partial indexes.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 21 Mar 2007 22:18:12 +0000 (22:18 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 21 Mar 2007 22:18:12 +0000 (22:18 +0000)
commit54d20024c1dad339acc8624d7ca902b762fe0844
tree107270059759b4e114b661838d896da4f4df8ada
parent2b49e5d3cb8b6a71797969c50f5c247f232de989
Fix some problems with selectivity estimation for partial indexes.

First, genericcostestimate() was being way too liberal about including
partial-index conditions in its selectivity estimate, resulting in
substantial underestimates for situations such as an indexqual "x = 42"
used with an index on x "WHERE x >= 40 AND x < 50".  While the code is
intentionally set up to favor selecting partial indexes when available,
this was too much...

Second, choose_bitmap_and() was likewise easily fooled by cases of this
type, since it would similarly think that the partial index had selectivity
independent of the indexqual.

Fixed by using predicate_implied_by() rather than simple equality checks
to determine redundancy.  This is a good deal more expensive but I don't
see much alternative.  At least the extra cost is only paid when there's
actually a partial index under consideration.

Per report from Jeff Davis.  I'm not going to risk back-patching this,
though.
src/backend/optimizer/path/indxpath.c
src/backend/utils/adt/selfuncs.c
src/test/regress/expected/select.out
src/test/regress/sql/select.sql