From: Oliver Jowett <oliver@opencloud.com>
To: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
Cc: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Cc: pgsql-hackers@postgresql.org
Subject: Re: prepareThreshold=1 and statement.executeBatch() ??
Date: Sun, 13 Nov 2005 23:09:24 +1300
Message-ID: <437710D4.3080908@opencloud.com> (raw)
In-Reply-To: <Pine.BSO.4.61.0511130350580.6118@leary.csoft.net>
References: <1131864485.6535.26.camel@Panoramix>
<Pine.BSO.4.61.0511130350580.6118@leary.csoft.net>
> On Sun, 13 Nov 2005, Joost Kraaijeveld wrote:
>
>> I have a connection that is created with "prepareThreshold=1" in the
>> connection string. I use a prepared statement that I fill with
>> addbatch() and that I execute with executeBatch() (for full source: see
>> "application.java" attachment).
>>
>> LOG: statement: PREPARE S_2 AS update prototype.customers set title=
>> $1 , defaultcurrency=$2, defaulttermsofdelivery=$3 ,
>> defaulttermsofpayment=$4 where customernumber=$5
>> LOG: statement: <BIND>
>> LOG: statement: EXECUTE <unnamed> [PREPARE: update
>> prototype.customers set title=$1 , defaultcurrency=$2, defaultter
>> msofdelivery=$3, defaulttermsofpayment=$4 where customernumber=$5]
>> LOG: duration: 773.841 ms
>> LOG: statement: <BIND>
>> LOG: statement: EXECUTE <unnamed> [PREPARE: update
>> prototype.customers set title=$1 , defaultcurrency=$2, defaultter
>> msofdelivery=$3, defaulttermsofpayment=$4 where customernumber=$5]
>> LOG: duration: 377.981 ms
>>
>> Does this output mean that the prepared statement with the name "S_2" is
>> not used in the following 2 EXECUTE statements and that therefor each
>> execute statement is planned again?
The driver does not actually issue PREPARE or EXECUTE statements; the
server is pretending that the protocol-level Prepare/Bind/Execute
messages are actually something issuing PREPARE/EXECUTE at the SQL level
(but in reality, nothing is issuing precisely the queries that are being
logged -- the query that is submitted is just your plain "update ..."
query).
The PREPARE S_2 AS .. logs that a Prepare message was processed (for the
query "update ..."). This does parsing/planning work and creates a named
prepared statement called S_2 on the server.
The <BIND> means that some previously prepared statement (you can't tell
which statement from what is logged! -- but it's S_2 in this case) is
being bound to parameter values via a Bind message, creating an unnamed
portal.
The EXECUTE <unnamed> means the unnamed portal is being executed via an
Execute message. It also logs the underlying statement at that point,
but not the statement name (!).
So if I read the logs right, the single prepared statement S_2 *is*
being reused in the case above.
Yes, it's a horribly confusing way for the server to log things. I
raised it on -hackers earlier in the 8.1 cycle, but I've not had time to
work on it myself.
-O
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: oliver@opencloud.com, J.Kraaijeveld@Askesis.nl, books@ejurka.com, pgsql-hackers@postgresql.org
Subject: Re: prepareThreshold=1 and statement.executeBatch() ??
In-Reply-To: <437710D4.3080908@opencloud.com>
References: <1131864485.6535.26.camel@Panoramix> <Pine.BSO.4.61.0511130350580.6118@leary.csoft.net> <437710D4.3080908@opencloud.com>
* 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