• Tom Lane's avatar
    Tweak index costing for problems with partial indexes. · 21a39de5
    Tom Lane authored
    btcostestimate() makes an estimate of the number of index tuples that will
    be visited based on knowledge of which index clauses can actually bound the
    scan within nbtree.  However, it forgot to account for partial indexes in
    this calculation, with the result that the cost of the index scan could be
    significantly overestimated for a partial index.  Fix that by merging the
    predicate with the abbreviated indexclause list, in the same way as we do
    with the full list to estimate how many heap tuples will be visited.
    
    Also, slightly increase the "fudge factor" that's meant to give preference
    to smaller indexes over larger ones.  While this is applied to all indexes,
    it's most important for partial indexes since it can be the only factor
    that makes a partial index look cheaper than a similar full index.
    Experimentation shows that the existing value is so small as to easily get
    swamped by noise such as page-boundary-roundoff behavior.  I'm tempted to
    kick it up more than this, but will refrain for now.
    
    Per report from Ruben Blanco.  These are long-standing issues, but given
    the lack of prior complaints I'm not going to risk changing planner
    behavior in back branches by back-patching.
    21a39de5
selfuncs.c 205 KB