Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 6D2D12E00A0 for ; Tue, 27 Nov 2007 12:55:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 60953-09 for ; Tue, 27 Nov 2007 12:55:49 -0400 (AST) Received: from main2.mycybernet.net (main2.mycybernet.net [209.222.63.140]) by postgresql.org (Postfix) with ESMTP id B978E2E008D for ; Tue, 27 Nov 2007 12:55:49 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227] helo=crankycanuck.ca) by main2.mycybernet.net with esmtp (Exim 4.62) (envelope-from ) id 1Ix3iv-0003Jg-4h for pgsql-performance@postgresql.org; Tue, 27 Nov 2007 11:55:49 -0500 Received: by crankycanuck.ca (Postfix, from userid 1000) id C5918504FC; Tue, 27 Nov 2007 11:55:43 -0500 (EST) Date: Tue, 27 Nov 2007 11:55:43 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Query only slow on first run Message-ID: <20071127165543.GY11978@crankycanuck.ca> Mail-Followup-To: Andrew Sullivan , 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.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/318 X-Sequence-Number: 27733 On Tue, Nov 27, 2007 at 05:33:36PM +0100, cluster wrote: > I have a query that takes about 7000 ms in average to complete the first > time it runs. Subsequent runs complete in only 50 ms. That is more than > a factor 100 faster! How can I make the query perform good in the first > run too? Probably by buying much faster disk hardware. You'll note that the query plans you posted are the same, except for the actual time it took to get the results back. That tells me you have slow storage. On subsequent runs, the data is cached, so it's fast. A -- Andrew Sullivan Old sigs will return after re-constitution of blue smoke