X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EC7859DC9C5 for ; Thu, 5 Jan 2006 15:19:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 58536-05 for ; Thu, 5 Jan 2006 15:19:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from frank.wiles.org (frank.wiles.org [24.124.39.75]) by postgresql.org (Postfix) with ESMTP id 77D309DC857 for ; Thu, 5 Jan 2006 15:19:51 -0400 (AST) Received: from kungfu (frank.wiles.org [127.0.0.1]) by frank.wiles.org (8.13.1/8.13.1) with SMTP id k05JJiBZ005253; Thu, 5 Jan 2006 13:19:44 -0600 Date: Thu, 5 Jan 2006 13:20:06 -0600 From: Frank Wiles To: "Andy" Cc: pgsql-performance@postgresql.org Subject: Re: Improving Inner Join Performance Message-Id: <20060105132006.19c7cd31.frank@wiles.org> In-Reply-To: <001d01c6120b$0d783600$0b00a8c0@forge> References: <001d01c6120b$0d783600$0b00a8c0@forge> X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.6.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.04 required=5 tests=[AWL=0.040] X-Spam-Score: 0.04 X-Spam-Level: X-Archive-Number: 200601/23 X-Sequence-Number: 16501 On Thu, 5 Jan 2006 17:16:47 +0200 "Andy" wrote: > Hi to all, > > I have the following query: > > SELECT count(*) FROM orders o > INNER JOIN report r ON r.id_order=o.id > WHERE o.id_status>3 > How can I improve this query's performace?? The ideea is to count all > the values that I have in the database for the following conditions. > If the users puts in some other search fields on the where then the > query runs faster but in this format sometimes it takes a lot lot of > time(sometimes even 2,3 seconds). > > Can this be tuned somehow??? Do you have an index on report.id_order ? Try creating an index for it if not and run a vacuum analyze on the table to see if it gets rid of the sequence scan in the plan. --------------------------------- Frank Wiles http://www.wiles.org ---------------------------------