Re: Indices for both where and order by.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Indices for both where and order by.
Дата
Msg-id 23445.1022185316@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Indices for both where and order by.  (Niclas Gustafsson <Niclas.Gustafsson@codesense.com>)
Список pgsql-general
Niclas Gustafsson <Niclas.Gustafsson@codesense.com> writes:
> Select * from hs where tcode = 'XXZZ' order by timestamp

> An idea was to create an Index on both tcode and timestamp, like this
> Create index hs_tcode_timestamp_idx on hs (tcode, timestamp)

> Am I completely wrong here, or could the planner not use it for both the
> where and the sorting?

You'd have to write
  Select * from hs where tcode = 'XXZZ' order by tcode, timestamp
to get the planner to realize that the index ordering is what's wanted.

            regards, tom lane

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

Предыдущее
От: Jan Wieck
Дата:
Сообщение: Re: Stored Procedure Problem
Следующее
От: "Peter A. Daly"
Дата:
Сообщение: Index Creation is slow after server change