Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 0B2919F9F46 for ; Wed, 20 Dec 2006 16:41:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 24478-08 for ; Wed, 20 Dec 2006 16:41:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id E198D9FA42F for ; Wed, 20 Dec 2006 16:41:41 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 20 Dec 2006 12:41:39 -0800 Subject: Re: parametrized statements, but always replan? From: Mark Lewis To: Kevin Murphy Cc: pgsql-jdbc@postgresql.org In-Reply-To: <45899296.9040008@genome.chop.edu> References: <45899296.9040008@genome.chop.edu> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Wed, 20 Dec 2006 12:41:39 -0800 Message-Id: <1166647299.7947.124.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27.rhel4.6) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/103 X-Sequence-Number: 16335 Set the prepareThreshold to 0, meaning that it will never create a "real" server-side prepared statement. There will still be a protocol level PREPARE/BIND/EXECUTE passed to the back-end because that's the way the V3 protocol works, but that's not the same thing. The planner will still see the actual query values. -- Mark Lewis On Wed, 2006-12-20 at 14:44 -0500, Kevin Murphy wrote: > 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 > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match