Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id B1BB9475E0A for ; Thu, 23 May 2002 16:26:08 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id A5E8647594B for ; Thu, 23 May 2002 16:22:07 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g4NKLuW23448; Thu, 23 May 2002 16:21:56 -0400 (EDT) To: Niclas Gustafsson Cc: 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> Comments: In-reply-to Niclas Gustafsson message dated "Thu, 23 May 2002 21:39:38 +0200" Date: Thu, 23 May 2002 16:21:56 -0400 Message-ID: <23445.1022185316@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200205/856 X-Sequence-Number: 24836 Niclas Gustafsson 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