Re: BUG #8576: 'btree index keys must be ordered by attribute'

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #8576: 'btree index keys must be ordered by attribute'
Дата
Msg-id 17519.1383431162@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #8576: 'btree index keys must be ordered by attribute'  (peter.hicks@poggs.co.uk)
Ответы Re: BUG #8576: 'btree index keys must be ordered by attribute'
Список pgsql-bugs
peter.hicks@poggs.co.uk writes:
> The SQL code further down allows a btree index to be created with the same
> column twice, however no queries are possible on the table and are met with
> a "ERROR: XX000: btree index keys must be ordered by attribute".

> It looks like bug #6351
> (http://www.postgresql.org/message-id/E1RdRfu-0004E9-8N@wrigleys.postgresql.org)
> - was this ever fixed for 9.1.x?

It was not, and won't be; the changes required to fix it properly seemed
too invasive to back-patch, especially considering that you can easily
avoid the bug.

            regards, tom lane


Author: Tom Lane <tgl@sss.pgh.pa.us>
Branch: master Release: REL9_2_BR [e2c2c2e8b] 2011-12-23 18:45:14 -0500

    Improve planner's handling of duplicated index column expressions.

    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.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Branch: master Release: REL9_2_BR [472d3935a] 2011-12-24 19:03:21 -0500

    Rethink representation of index clauses' mapping to index columns.

    In commit e2c2c2e8b1df7dfdb01e7e6f6191a569ce3c3195 I made use of nested
    list structures to show which clauses went with which index columns, but
    on reflection that's a data structure that only an old-line Lisp hacker
    could love.  Worse, it adds unnecessary complication to the many places
    that don't much care which clauses go with which index columns.  Revert
    to the previous arrangement of flat lists of clauses, and instead add a
    parallel integer list of column numbers.  The places that care about the
    pairing can chase both lists with forboth(), while the places that don't
    care just examine one list the same as before.

    The only real downside to this is that there are now two more lists that
    need to be passed to amcostestimate functions in case they care about
    column matching (which btcostestimate does, so not passing the info is not
    an option).  Rather than deal with 11-argument amcostestimate functions,
    pass just the IndexPath and expect the functions to extract fields from it.
    That gets us down to 7 arguments which is better than 11, and it seems
    more future-proof against likely additions to the information we keep
    about an index path.

В списке pgsql-bugs по дате отправления:

Предыдущее
От: peter.hicks@poggs.co.uk
Дата:
Сообщение: BUG #8576: 'btree index keys must be ordered by attribute'
Следующее
От: mgr inż. Jacek Bzdak
Дата:
Сообщение: Fwd: Problems with pg_stat_activity view