Skip site navigation (1) Skip section navigation (2)

Re: Under what circumstances does PreparedStatement use stored plans?

From: "Chris Smith" <cdsmith(at)twu(dot)net>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Under what circumstances does PreparedStatement use stored plans?
Date: 2004-04-13 19:42:12
Message-ID: 016a01c4218f$6eff94e0$6f00000a@KYA (view raw or flat)
Thread:
Lists: pgsql-jdbc
Tom Lane wrote:
> I think that is a safe bet to be true, as long as you get *some*
> mileage out of the plan cache.  If the application issues a bunch of
> no-two-alike queries then it's a loss of course.  But doesn't the JDBC
> API distinguish prepared statements from unprepared ones?  ISTM it is
> the app programmer's responsibility to prepare just those statements
> he's likely to use more than once.  I don't think the driver need
> second-guess this choice.

That's true; JDBC makes a distinction between prepared statements and
non-prepared statements.

From a practical matter, though, application developers often use
PreparedStatement when they don't plan to re-use the query.  This is primarily
because it adds to portability; using PreparedStatement.setDate to set a
parameterized date field in a query doesn't require the application developer
to know the proper String representation of the date (which differs, for
example, with Access as the database).

So on one hand, the distinction isn't made so cleanly in the real world.  On
the other hand, there's a compelling argument that a developer who uses
PreparedStatement for a one-shot query simply to avoid handling portability in
a more comprehensive way should expect poor optimization behavior on behalf of
the database.

-- 
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


In response to

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2004-04-13 21:18:12
Subject: Re: Under what circumstances does PreparedStatement use stored
Previous:From: James RobinsonDate: 2004-04-13 19:19:28
Subject: Re: Under what circumstances does PreparedStatement use stored plans?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group