Re: Indices for both where and order by. - Mailing list pgsql-general

From Tom Lane
Subject Re: Indices for both where and order by.
Date
Msg-id 23445.1022185316@sss.pgh.pa.us
Whole thread Raw
In response to Indices for both where and order by.  (Niclas Gustafsson <Niclas.Gustafsson@codesense.com>)
List 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 by date:

Previous
From: Jan Wieck
Date:
Subject: Re: Stored Procedure Problem
Next
From: "Peter A. Daly"
Date:
Subject: Index Creation is slow after server change