Re: Query preparation

From: John Lister <john(dot)lister-ps(at)kickstone(dot)com>
To: Oliver Jowett <oliver(at)opencloud(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Query preparation
Date: 2009-04-14 17:19:02
Message-ID: 49E4C586.4070107@kickstone.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Oliver Jowett wrote
> John Lister wrote:
>
>> Hi, i was wondering if there is any reason why the query preparation is
>> done when the query is executed instead of when the preparedStatement is
>> created.
>>
>
> It would be an extra network round-trip on every query, and there's no
> requirement to prepare it early.
>
>
I'm not sure why it would be there would be an extra round trip? The
parse is done anyway, the only extra round trip would be if you did a
describe (which admittedly i'm looking into optionally doing for binary
transfers) or if you didn't use the preparedStatement to do any queries
which is i'd imagine is rare.

Maybe i've missed something?

>> Has any one looked into moving it?
>>
>
> Why would you want to move it?
>
>

To me it would be cleaner, it looks like the current driver was written
prior to v3 of the protocol where only simple queries are used and
everything is transmitted as text. The extended protocol stuff has been
bolted subsequently to the execute part of the driver rather than doing
it when the query is prepared... btw, i have nothing but respect for the
writers after doing some work on the another driver some years ago.

Also, in fairness i've done a lot of work with the oracle stuff vwhich
create portals (cursors) and prepare the statement before the execution
and this makes more sense to me.

Also, with regard to extra network traffic and latency i'm not
suggesting changing the way normal statements are used, only
PreparedStatements. This to me fits in more with the way the JDBC spec
is worded and i'd guess the more usual use case of statements -
Statement for quick and dirty one off queries, PreparedStatement for
more complicated/multiple use queries.

JOHN

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message John Lister 2009-04-14 20:29:00 Re: Query preparation
Previous Message Oliver Jowett 2009-04-14 15:41:32 Re: Query preparation