X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5B05F474E44 for ; Wed, 9 Apr 2003 14:56:11 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id BEBF5474E42 for ; Wed, 9 Apr 2003 14:56:06 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 068E8D614; Wed, 9 Apr 2003 11:56:06 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id F06255C0B; Wed, 9 Apr 2003 11:56:06 -0700 (PDT) Date: Wed, 9 Apr 2003 11:56:06 -0700 (PDT) From: Stephan Szabo To: Cris Cc: Subject: Re: Index not used, In-Reply-To: <200304091842.h39IgHe21800@cancerberus.com> Message-ID: <20030409115454.P68720-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Status: No, hits=-25.8 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, 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/157 X-Sequence-Number: 8312 On Wed, 9 Apr 2003, Cris wrote: > I've have this table: > > TABLE BB : There isn't any primary key, and is it more or less order (I mean, tt always is increased in each row, and id is > nearly ordered) > ex: > > id, op, atr, tt > > 1 0 X, 1 > 2 0 A 3 > 3 0 X 5 > .......... > 1 0 X 51 > ....... > 85 1 l 150 > 86 2 po 155 > 2 0 X 178 > 87 3 1 189 > .... > > I VACUUM ANALYZE each 10.000 inserts more or less > in my case op only can have 3 values; > 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. > but, after an hour running the program (more than 90.000 rows), I stopped it and > "EXPAIN SELECT * FROM BB WHERE id="+ id+" AND op=0 order by tempst desc;"; > But, my sorprise was that the index wasn't be used. Always do a Seq Scan. What is the actual explain output?