Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 7B7179F9F46 for ; Wed, 20 Dec 2006 15:44:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 37699-03 for ; Wed, 20 Dec 2006 15:44:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from genomemail.chop.edu (genomemail.chop.edu [159.14.214.193]) by postgresql.org (Postfix) with ESMTP id 0963E9F9DAD for ; Wed, 20 Dec 2006 15:44:23 -0400 (AST) Received: from [159.14.214.141] ([159.14.214.141]) BY genomemail.chop.edu ([159.14.214.193]) WITH ESMTP (4D WebSTAR V Mail (5.3.4)); Wed, 20 Dec 2006 14:44:22 -0500 Message-ID: <45899296.9040008@genome.chop.edu> Date: Wed, 20 Dec 2006 14:44:22 -0500 From: Kevin Murphy User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.8) Gecko/20061025 Thunderbird/1.5.0.8 Mnenhy/0.7.4.666 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: parametrized statements, but always replan? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/101 X-Sequence-Number: 16333 Sorry for the newbie question here. The documentation (documentation/81/server-prepare.html) isn't clear about this point. I'm using PG 8.1 with the matching jdbc driver. Will the following code execute the query with a custom plan based on the value of var (assuming no use of the prepare threshold)? prestmt = conn.prepareStatement(query); prestmt.setString(1, var); resultSet = prestmt.executeQuery(); // ... use result set ... resultSet.close(); prestmt.close(); I'd like the safety of parametrized SQL statements combined with the greater performance (for certain queries) of having every statement planned based on the specific parameters. Ideally, I'd like to use prepareStatement() and executeQuery() with out-of-band parameters, but have the finished statement be custom-planned. Most of my queries wouldn't benefit from the "plan once, execute many times" model. I've read documentation/81/server-prepare.html, but somehow it wasn't clear. It makes it sound as if by default, server-side prepared statements are not really used ("There are a number of ways to enable server side prepared statements ..."), which would be good for me. But looking at my postgresql log, that doesn't seem to be the case; I see PREPARE, BIND, and EXECUTE lines for each query. Thanks, Kevin Murphy