X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id EECB1475458 for ; Wed, 9 Apr 2003 15:28:33 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 2D478474E42 for ; Wed, 9 Apr 2003 15:28:33 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h39JSS2L009520; Wed, 9 Apr 2003 15:28:29 -0400 (EDT) To: Cris Cc: pgsql-admin@postgresql.org Subject: Re: Index not used, In-reply-to: <20030409115454.P68720-100000@megazone23.bigpanda.com> References: <20030409115454.P68720-100000@megazone23.bigpanda.com> Comments: In-reply-to Stephan Szabo message dated "Wed, 09 Apr 2003 11:56:06 -0700" Date: Wed, 09 Apr 2003 15:28:28 -0400 Message-ID: <9519.1049916508@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/160 X-Sequence-Number: 8315 Stephan Szabo writes: > On Wed, 9 Apr 2003, Cris wrote: >> I've created an index on (id,op,tt) to improve the next query, that is executed very often: >> "SELECT * FROM BB WHERE id="+ id+" AND op=0 order by tt desc;"; >> (because the only row I need is the one that has the highest tt) > You might want to use limit 1 then to prevent it from getting all the rest > of the rows as well. Also, I think you'll need to say "ORDER BY id, op, tt" to get it to realize that the index matches the required ordering. regards, tom lane