Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 61FAC9FBB42 for ; Fri, 9 Mar 2007 15:58:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 18415-06 for ; Fri, 9 Mar 2007 15:58:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 41FCF9FBA4C for ; Fri, 9 Mar 2007 15:58:33 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Fri, 9 Mar 2007 19:58:31 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 09 Mar 2007 13:58:31 -0600 Subject: Re: index not being used. Why? From: Scott Marlowe To: Gerardo Herzig Cc: pgsql-sql@postgresql.org In-Reply-To: <45F176CA.3050107@fmed.uba.ar> References: <45F176CA.3050107@fmed.uba.ar> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1173470311.20651.302.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Fri, 09 Mar 2007 13:58:31 -0600 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.044 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_PASS, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200703/131 X-Sequence-Number: 27769 On Fri, 2007-03-09 at 09:01, Gerardo Herzig wrote: > Hi all. I have this 2 relations > SNIP > Index Cond: ((upper((word)::text) ~>=~ 'TEST'::character varying) AND (upper((word)::text) ~<~'TESU'::character varying)) > -> Hash (cost=9.08..9.08 rows=408 width=55) > -> Seq Scan on pages (cost=0.00..9.08 rows=408 width=55) > > (8 rows) > > > Watch the last row of the explain command. It makes a sequential scan > on the pages table, like it is not using the index on the "id" field. > > The result itself is OK, but i will populate the tables so i think > that later that sequential scan would be a problem. Welcome to the world of tomorrow! hehe. PostgreSQL uses a cost based planner. It decided that an index would cost more than a seq scan, so it chose the seq scan. As mentioned in other posts, you'll need to do an analyze. Also, look up things like vacuum / autovacuum as well. > Im using postgres 8.1.3 You need to upgrade to 8.1.8 or whatever the latest version is by the time this email gets to you :) 8.1.3 is about a year out of date.