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 C1F409FA4A7 for ; Fri, 30 Jun 2006 11:29:08 -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 01654-10 for ; Fri, 30 Jun 2006 11:28:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (mail.logix-tt.com [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id C302F9FA163 for ; Fri, 30 Jun 2006 11:28:56 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (T916d.t.pppool.de [89.55.145.109]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 147F065874 for ; Fri, 30 Jun 2006 16:30:33 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 9B62B181C1C6E for ; Fri, 30 Jun 2006 16:29:06 +0200 (CEST) Message-ID: <44A53532.50402@logix-tt.com> Date: Fri, 30 Jun 2006 16:29:06 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Thunderbird 1.5.0.2 (X11/20060516) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Index Being Ignored? References: In-Reply-To: X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/496 X-Sequence-Number: 19853 Hi, Joe, Joe Lester wrote: > 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) The query planner estimates that your filter will hit 286882 rows, while in reality it hits only 7458 rows. That's why the query planer chooses a sequential scan. It seems that the statistics for the column expected_quantity are off. My suggestions: - make shure that the statistics are current by analyzing the table appropriately (e. G. by using the autovacuum daemon from contrib). - increase the statistics target for this column. - if you run this query very often, an conditional index might make sense: CREATE INDEX purchase_order_having_quantity_idx ON purchase_order_items (expected_quantity) WHERE expected_quantity > 0; HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org