X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 65A8A9FA0EC for ; Fri, 30 Jun 2006 15:21:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 93349-02 for ; Fri, 30 Jun 2006 15:21:30 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx2.surnet.cl (mx2.surnet.cl [216.155.73.181]) by postgresql.org (Postfix) with ESMTP id 8A2FE9FA192 for ; Fri, 30 Jun 2006 15:21:29 -0300 (ADT) Received: from unknown (HELO alvh.no-ip.org) ([201.221.201.100]) by mx2.surnet.cl with ESMTP; 30 Jun 2006 10:14:54 -0400 X-IronPort-AV: i="4.06,193,1149480000"; d="scan'208"; a="62782738:sNHT18989024" Received: by alvh.no-ip.org (Postfix, from userid 1000) id 5118DC22E96; Fri, 30 Jun 2006 10:14:55 -0400 (CLT) Date: Fri, 30 Jun 2006 10:14:55 -0400 From: Alvaro Herrera To: Joe Lester Cc: pgsql-performance@postgresql.org Subject: Re: Index Being Ignored? Message-ID: <20060630141455.GC21718@surnet.cl> Mail-Followup-To: Joe Lester , pgsql-performance@postgresql.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.11+cvs20060403 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/503 X-Sequence-Number: 19860 Joe Lester wrote: > I have a index question. My table has 800K rows and I a doing a basic > query on an indexed integer field which takes over 2 seconds to > complete because it's ignoring the index for some reason. Any ideas > as to why it's ignoring the index? I'm using postgres 8.0.2. > > SELECT count(*) FROM purchase_order_items WHERE expected_quantity > '0' > > EXPLAIN ANALYZE reveals that it's not using the index... > > Aggregate (cost=22695.28..22695.28 rows=1 width=0) (actual > time=2205.688..2205.724 rows=1 loops=1) > -> Seq Scan on purchase_order_items (cost=0.00..21978.08 > rows=286882 width=0) (actual time=0.535..2184.405 rows=7458 loops=1) > Filter: (expected_quantity > 0) > Total runtime: 2207.203 ms The estimated rowcount is far off. When did you last run ANALYZE on this table? BTW, you should upgrade (to 8.0.8) unless you want known bugs to destroy your data. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support