Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4A8AC64FD97 for ; Wed, 31 Dec 2008 12:01:30 -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 92355-08 for ; Wed, 31 Dec 2008 12:01:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lists.commandprompt.com (host-159.commandprompt.net [207.173.203.159]) by mail.postgresql.org (Postfix) with ESMTP id 385D664FFD4 for ; Wed, 31 Dec 2008 12:01:25 -0400 (AST) Received: from perhan.alvh.no-ip.org (200-85-208-106.bk4-dsl.surnet.cl [200.85.208.106]) (authenticated bits=0) by lists.commandprompt.com (8.13.8/8.13.8) with ESMTP id mBVG6gsU001155 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 31 Dec 2008 08:06:45 -0800 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 81ECA47CCE; Wed, 31 Dec 2008 13:01:18 -0300 (CLST) Date: Wed, 31 Dec 2008 13:01:18 -0300 From: Alvaro Herrera To: Tom Lane Cc: Scott Carey , bricklen , Scott Marlowe , Merlin Moncure , "pgsql-performance@postgresql.org" Subject: Re: Poor plan choice in prepared statement Message-ID: <20081231160118.GE3809@alvh.no-ip.org> References: <33b743250812301059u31ce82faw3d72a38280b37402@mail.gmail.com> <2796.1230678149@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2796.1230678149@sss.pgh.pa.us> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (lists.commandprompt.com [207.173.203.159]); Wed, 31 Dec 2008 08:06:46 -0800 (PST) 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/243 X-Sequence-Number: 32279 Tom Lane escribió: > 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. I think it has been shown enough times that the performance drop caused by a worse plan can be orders of magnitudes worse than what's gained by producing the plan only once. It does not seem a bad idea to provide a way to carry out only the parse phase, and postpone planning until the parameters have been received. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.