X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id B4BCCD1B53F for ; Mon, 13 Oct 2003 21:34:18 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 43626-05 for ; Mon, 13 Oct 2003 18:33:47 -0300 (ADT) Received: from phaedrusdeinus.org (dsl092-130-239.chi1.dsl.speakeasy.net [66.92.130.239]) by svr1.postgresql.org (Postfix) with SMTP id 225E8D1B4E3 for ; Mon, 13 Oct 2003 18:33:46 -0300 (ADT) Received: (qmail 53286 invoked by uid 1001); 13 Oct 2003 16:19:59 -0000 Date: Mon, 13 Oct 2003 11:19:59 -0500 From: johnnnnnn To: pgsql-performance@postgresql.org, Chris Faulkner Subject: Re: sql performance and cache Message-ID: <20031013161959.GA29900@performics.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/434 X-Sequence-Number: 4182 On Sat, Oct 11, 2003 at 10:43:04AM +0100, Chris Faulkner wrote: > I have two very similar queries which I need to execute. They both > have exactly the same from / where conditions. When I execute the > first, it takes about 16 seconds. The second is executed almost > immediately after, it takes 13 seconds. In short, I'd like to know > why the query result isn't being cached and any ideas on how to > improve the execution. The way to do the type of caching you're talking about, if i understand you correctly, would be to create a temporary table. Specifically, create a temporary table with the results of the second query. Then run a select * on that table (with no where clause), and follow it with a select max(replace(...)) on the same table (no where clause). That guarantees two things: 1- The joins/filters are not parsed and evaluated twice, with the corresponding disk reads. 2- The data is exactly consistent between the two queries. Correct me if i misunderstood your problem. -johnnnnnnnnnn