Re: Any better plan for this query?..

Поиск
Список
Период
Сортировка
От Simon Riggs
Тема Re: Any better plan for this query?..
Дата
Msg-id 1242739192.14551.204.camel@ebony.2ndQuadrant
обсуждение исходный текст
Ответ на Re: Any better plan for this query?..  (Matthew Wakeling <matthew@flymine.org>)
Список pgsql-performance
On Tue, 2009-05-19 at 13:01 +0100, Matthew Wakeling wrote:

> That leads me on to another topic. Consider the query:
>
> SELECT * FROM table ORDER BY a, b
>
> where the column "a" is declared UNIQUE and has an index. Does Postgres
> eliminate "b" from the ORDER BY, and therefore allow fetching without
> sorting from the index?

No, because we don't use unique constraints much at all to infer things.

> Or how about this query:
>
> SELECT * FROM table1, table2 WHERE table1.fk = table2.id ORDER BY
>      table1.id, table2.id
>
> where both "id" columns are UNIQUE with an index. Do we eliminate
> "table2.id" from the ORDER BY in this case?

Yes, that is eliminated via equivalence classes.

--
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


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

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Re: Any better plan for this query?..
Следующее
От: Scott Carey
Дата:
Сообщение: Re: Any better plan for this query?..