Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 6C4DE64FD22 for ; Tue, 30 Dec 2008 19:16:59 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 11427-07 for ; Tue, 30 Dec 2008 19:16:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from bifrost.lang.hm (mail.lang.hm [64.81.33.126]) by mail.postgresql.org (Postfix) with ESMTP id A870464FD18 for ; Tue, 30 Dec 2008 19:16:55 -0400 (AST) Received: from asgard.lang.hm (asgard.lang.hm [10.0.0.100]) by bifrost.lang.hm (8.13.4/8.13.4/Debian-3) with ESMTP id mBUNGpZu012504; Tue, 30 Dec 2008 15:16:51 -0800 Date: Tue, 30 Dec 2008 16:19:01 -0800 (PST) From: david@lang.hm X-X-Sender: dlang@asgard.lang.hm To: Tom Lane cc: Scott Carey , bricklen , Scott Marlowe , Merlin Moncure , "pgsql-performance@postgresql.org" Subject: Re: Poor plan choice in prepared statement In-Reply-To: <2796.1230678149@sss.pgh.pa.us> Message-ID: References: <33b743250812301059u31ce82faw3d72a38280b37402@mail.gmail.com> , <33b743250812301214k7a0ec4fby614d693ec7915d3@mail.gmail.com> <2796.1230678149@sss.pgh.pa.us> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/239 X-Sequence-Number: 32275 On Tue, 30 Dec 2008, Tom Lane wrote: > Scott Carey writes: >> I have also had a case where one query would take a couple hundred ms to parse, but was fairly fast to plan and execute (1/3 the parse cost) -- yet another case where a prepared statement that re-plans each execution would be helpful. At least you can prevent SQL injection and cut the parse cost. Its not all about the cost of planning the query. > > The point of a prepared statement IMHO is to do the planning only once. > There's necessarily a tradeoff between that and having a plan that's > perfectly adapted to specific parameter values. actually, it does two things 1. planning only once 2. parsing only once. I suspect that when this was initially setup the expectation was that the planning was the expensive thing that should be avoided. in this case a post earlier in the thread identified parsing of the query as being the expensive thing (planning + execution was 1/3 the cost of the parsing) since there is not a pre-parsed interface for queries, it may make sense to setup a way to have the query pre-parsed, but not pre-planned for cases like this. David Lang