Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id F3CE4475972 for ; Fri, 17 May 2002 12:43:36 -0400 (EDT) Received: from prod1-int.codesense.com (unknown [193.10.39.189]) by postgresql.org (Postfix) with ESMTP id 2066A475AEF for ; Fri, 17 May 2002 12:41:56 -0400 (EDT) Received: from gmg (gmg.codesense.com [192.168.0.183]) by prod1-int.codesense.com (8.11.4/8.11.4) with ESMTP id g4HAeTv02549 for ; Fri, 17 May 2002 12:40:29 +0200 From: "Niclas Gustafsson" To: Subject: Indices for both where and order by. Date: Fri, 17 May 2002 12:54:00 +0200 Organization: CodeSense AB Message-ID: <007801c1fd91$270f6490$b700a8c0@gmg> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.3416 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300 Importance: Normal X-Archive-Number: 200205/147 X-Sequence-Number: 4322 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