• Tom Lane's avatar
    Improve planner's handling of duplicated index column expressions. · e2c2c2e8
    Tom Lane authored
    It's potentially useful for an index to repeat the same indexable column
    or expression in multiple index columns, if the columns have different
    opclasses.  (If they share opclasses too, the duplicate column is pretty
    useless, but nonetheless we've allowed such cases since 9.0.)  However,
    the planner failed to cope with this, because createplan.c was relying on
    simple equal() matching to figure out which index column each index qual
    is intended for.  We do have that information available upstream in
    indxpath.c, though, so the fix is to not flatten the multi-level indexquals
    list when putting it into an IndexPath.  Then we can rely on the sublist
    structure to identify target index columns in createplan.c.  There's a
    similar issue for index ORDER BYs (the KNNGIST feature), so introduce a
    multi-level-list representation for that too.  This adds a bit more
    representational overhead, but we might more or less buy that back by not
    having to search for matching index columns anymore in createplan.c;
    likewise btcostestimate saves some cycles.
    
    Per bug #6351 from Christian Rudolph.  Likely symptoms include the "btree
    index keys must be ordered by attribute" failure shown there, as well as
    "operator MMMM is not a member of opfamily NNNN".
    
    Although this is a pre-existing problem that can be demonstrated in 9.0 and
    9.1, I'm not going to back-patch it, because the API changes in the planner
    seem likely to break things such as index plugins.  The corner cases where
    this matters seem too narrow to justify possibly breaking things in a minor
    release.
    e2c2c2e8
indxpath.c 111 KB