Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id A64C6633E87 for ; Tue, 12 May 2009 12:59:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 78130-06 for ; Tue, 12 May 2009 12:59:13 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mk-filter-3-a-1.mail.uk.tiscali.com (mk-filter-3-a-1.mail.uk.tiscali.com [212.74.100.54]) by mail.postgresql.org (Postfix) with ESMTP id 019FD633E0E for ; Tue, 12 May 2009 12:59:13 -0300 (ADT) X-Trace: 194470566/mk-filter-3.mail.uk.tiscali.com/B2C/$b2c-THROTTLED-DYNAMIC/b2c-CUSTOMER-DYNAMIC-IP/80.225.59.140/None/john.lister@kickstone.com X-SBRS: None X-RemoteIP: 80.225.59.140 X-IP-MAIL-FROM: john.lister@kickstone.com X-SMTP-AUTH: X-MUA: Thunderbird 2.0.0.21 (Windows/20090302) X-IP-BHB: Once X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AroBAO84CUpQ4TuM/2dsb2JhbAAIzTiEAgU X-IronPort-AV: E=Sophos;i="4.41,183,1241391600"; d="scan'208";a="194470566" Received: from 80-225-59-140.dynamic.dial.as9105.com (HELO [192.168.6.11]) ([80.225.59.140]) by smtp.tiscali.co.uk with ESMTP; 12 May 2009 16:59:11 +0100 Message-ID: <4A099C8F.60709@kickstone.com> Date: Tue, 12 May 2009 16:58:07 +0100 From: John Lister User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Thomas Finneid CC: pgsql-jdbc@postgresql.org Subject: Re: pooled prepared statements References: <4A0978A3.6030900@fcon.no> In-Reply-To: <4A0978A3.6030900@fcon.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/64 X-Sequence-Number: 19614 Thomas Finneid wrote: > When a PreparedStatment is created by a pooled connection, as far as I > understand if, that creation happens on the server side, and a > reference, of sorts, is returned to the client jdbc. > > Is that prepared statement shared among the connections or is it only > available to that single connection? and more importantly, can many > connections use that prepared statement concurrently? > > If it is shared, then it must be usable by concurrent connections, > otherwise it will be difficult for the client to know if the statement > is occupied or not. So I just want to confirm that I understand how > the JDBC driver works. Once the query usage count exceeds the prepareThreshold parameter, then the driver does create a "prepare statement object" on the server. This is only valid for the time the PreparedStatement is open and only on that connection. So to answer your question, they cannot be shared by multiple connections. You can create your own using the PREPARE and EXECUTE sql commands so long as you track them across different connections... I'll admit this would be a nice feature for things like JPA where you end up creating lots of preparedStatements on different connections, reusing or caching a single one may be a worthwhile performance optimisation - although not sure about how you would implement it nicely.. JOHN