X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F1D1ADB5A7; Sun, 13 Nov 2005 06:09:31 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40702-06; Sun, 13 Nov 2005 10:09:29 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by svr1.postgresql.org (Postfix) with ESMTP id 42FB2DB5CF; Sun, 13 Nov 2005 06:09:29 -0400 (AST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1EbEnd-00088V-5z; Sun, 13 Nov 2005 23:09:25 +1300 Message-ID: <437710D4.3080908@opencloud.com> Date: Sun, 13 Nov 2005 23:09:24 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051009) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Joost Kraaijeveld CC: Kris Jurka , "pgsql-jdbc@postgresql.org" , pgsql-hackers@postgresql.org Subject: Re: prepareThreshold=1 and statement.executeBatch() ?? References: <1131864485.6535.26.camel@Panoramix> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.008] X-Spam-Score: 0.008 X-Spam-Level: X-Archive-Number: 200511/100 X-Sequence-Number: 14198 > 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: >> LOG: statement: EXECUTE [PREPARE: update >> prototype.customers set title=$1 , defaultcurrency=$2, defaultter >> msofdelivery=$3, defaulttermsofpayment=$4 where customernumber=$5] >> LOG: duration: 773.841 ms >> LOG: statement: >> LOG: statement: EXECUTE [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 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 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