pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Niclas Gustafsson <Niclas.Gustafsson@codesense.com>
To: pgsql-general@postgresql.org
Subject: Indices for both where and order by.
Date: Thu, 23 May 2002 21:39:38 +0200
Message-ID: <6987080184.20020523213938@codesense.com> (raw)
In-Reply-To: <007801c1fd91$270f6490$b700a8c0@gmg>
References: <007801c1fd91$270f6490$b700a8c0@gmg>

Hi all,

A quick question about indices...

I have a table with a couple of column, two of which I use in 
a query, one for the where and one for the order by.

Table look something like:
                 Table "hs"
  Attribute|         Type          |                          Modifier

-----------+-----------------------+------------------------------------
------------------------
 id        | integer               | not null default
nextval('"hs_id_seq"'::text)
 timeid    | integer               | 
 code      | character varying(12) | 
 tcode     | character varying(10) | 
 inst      | character varying(10) | 
 timestamp | integer               | 
.
.
.

The query I use is like this:

Select * from hs where tcode = 'XXZZ' order by timestamp
The table above contains something like 500 000 rows

If I create an index on the tcode I can speed the query up using an
index scan, however the 
Sorting is taking some time.

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?


Regards,

Niclas Gustafsson





view thread (3+ messages)  latest in thread

Message-ID: <6987080184.20020523213938@codesense.com>
Permalink:  ../6987080184.20020523213938@codesense.com/
Also on:    postgresql.org/message-id/6987080184.20020523213938@codesense.com

 · 

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: Niclas.Gustafsson@codesense.com, pgsql-general@postgresql.org
  Subject: Re: Indices for both where and order by.
  In-Reply-To: <6987080184.20020523213938@codesense.com>
  References: <007801c1fd91$270f6490$b700a8c0@gmg> <6987080184.20020523213938@codesense.com>

* 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