pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Niclas Gustafsson <Niclas.Gustafsson@codesense.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Indices for both where and order by.
Date: Thu, 23 May 2002 16:21:56 -0400
Message-ID: <23445.1022185316@sss.pgh.pa.us> (raw)
In-Reply-To: <6987080184.20020523213938@codesense.com>
References: <007801c1fd91$270f6490$b700a8c0@gmg>
	<6987080184.20020523213938@codesense.com>

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



view thread (3+ messages)

Message-ID: <23445.1022185316@sss.pgh.pa.us>
Permalink:  ../23445.1022185316@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23445.1022185316@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Niclas.Gustafsson@codesense.com, pgsql-general@postgresql.org
  Subject: Re: Indices for both where and order by.
  In-Reply-To: <23445.1022185316@sss.pgh.pa.us>
  References: <007801c1fd91$270f6490$b700a8c0@gmg> <6987080184.20020523213938@codesense.com> <23445.1022185316@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox