From: Kevin Murphy <murphy@genome.chop.edu>
To: pgsql-jdbc@postgresql.org
Subject: parametrized statements, but always replan?
Date: Wed, 20 Dec 2006 14:44:22 -0500
Message-ID: <45899296.9040008@genome.chop.edu> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: murphy@genome.chop.edu
Subject: Re: parametrized statements, but always replan?
In-Reply-To: <45899296.9040008@genome.chop.edu>
References: <45899296.9040008@genome.chop.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox