X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 31B2A476357; Wed, 9 Apr 2003 15:00:27 -0400 (EDT) Received: from mail.xythos.com (unknown [206.14.210.116]) by postgresql.org (Postfix) with ESMTP id E64BC47634E; Wed, 9 Apr 2003 15:00:25 -0400 (EDT) Received: from ravms by mail.xythos.com with mail-ok (Exim 3.36 #3) id 193Ko6-0007eA-00; Wed, 09 Apr 2003 19:00:26 +0000 Received: from localhost.localdomain ([127.0.0.1] helo=xythos.com) by mail.xythos.com with asmtp (Exim 3.36 #3) id 193Ko5-0007ds-00; Wed, 09 Apr 2003 19:00:25 +0000 Message-ID: <3E946DC5.9020304@xythos.com> Date: Wed, 09 Apr 2003 12:00:21 -0700 From: Barry Lind User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Cris Cc: pgsql-admin@postgresql.org, PostgreSQL JDBC Subject: Re: [JDBC] Index not used, References: <200304091842.h39IgHe21800@cancerberus.com> In-Reply-To: <200304091842.h39IgHe21800@cancerberus.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Envelope-To: cris@dmcid.net, pgsql-admin@postgresql.org, pgsql-jdbc@postgresql.org X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA 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/188 X-Sequence-Number: 8343 Cris, What version are you running and what are the datatypes of your columns? Prior to 7.3, postgres wouldn't use an index in the following case: column = 1 if the datatype of the column "column" wasn't integer. In order to get it to use the index you needed a cast, so if for example column was of type int8, you would use: column = 1::int8 so that both sides of the condition were the same datatype. Then the index would be used. thanks, --Barry Cris wrote: > Hi! > 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) > > 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. > > Have I to define the index in other columns? Have I to VACUUM ANALYZE more often? > > There is other option to avoid the sort that is done because of ORDER BY? > > Thanks a lot > > yours, > > Cris..