Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 11A5E632C47 for ; Thu, 15 Apr 2010 07:59:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 33107-07 for ; Thu, 15 Apr 2010 10:59:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f202.google.com (mail-iw0-f202.google.com [209.85.223.202]) by mail.postgresql.org (Postfix) with ESMTP id 87CDC632C0B for ; Thu, 15 Apr 2010 07:59:24 -0300 (ADT) Received: by iwn40 with SMTP id 40so513173iwn.1 for ; Thu, 15 Apr 2010 03:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:received:message-id:subject :from:to:cc:content-type; bh=2DSKVRc5TPJMFLhQBIzJGy+vSpX2gHyHmE6+xXjxn5w=; b=KZtqtUHDZv7HUNxhcpgiONiaP8oi1Gq0QCfn/ezTgOLeNVTKTO3BdY/Q4Xvmp0GZjy Ogtl2hWBZvZFYuVe6XWLJeOzi5zHRdg5ASfT02x97eEqwIQEhu5KUus0saasAwJPeFdc jLIbXtQqM928QvawGi76vc7jwUwrcxlZuNIrc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=nwi0o60UKlQgr20lQGUXBfKZutYvHy3hHRZxmDtok4atrwQKtKd8UpsVT/Zj40gbZK SOLa+Pk4uvyoJc7TyXoIebUvO7BwIL6B/AUmHQc+pOFJFLTIJ+o+NRb5QIXQkYtdkCqG 8IZhqE/PFGx7JtXtAn1x6hFP3MCfpjRPCBz6g= MIME-Version: 1.0 Received: by 10.231.173.201 with HTTP; Thu, 15 Apr 2010 03:59:22 -0700 (PDT) In-Reply-To: <4BC64B64.5070608@postnewspapers.com.au> References: <4BC64B64.5070608@postnewspapers.com.au> Date: Thu, 15 Apr 2010 06:59:22 -0400 X-Google-Sender-Auth: 1651ff299b0e6907 Received: by 10.231.174.140 with SMTP id t12mr3883207ibz.89.1271329162678; Thu, 15 Apr 2010 03:59:22 -0700 (PDT) Message-ID: Subject: Re: JDBC question for PG 8.3.9 From: Dave Cramer To: Craig Ringer Cc: Dave Crooke , pgsql-performance Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201004/183 X-Sequence-Number: 38433 On Wed, Apr 14, 2010 at 7:10 PM, Craig Ringer wrote: > On 15/04/10 04:49, Dave Crooke wrote: >> >> Hi foilks >> >> I am using PG 8.3 from Java. I am considering a performance tweak which >> will involve holding about 150 java.sql.PreparedStatment objects open >> against a single PGSQL connection. Is this safe? >> >> I know that MySQL does not support prepared statements /per se/, and so >> their implementation of PreparedStatement is nothing more than some >> client-side convenience code that knows how to escape and format >> constants for you. Is this the case for PG, or does the PG JDBC driver >> do the real thing? > > Pg supports real server-side prepared statements, as does the JDBC driver. > > IIRC (and I can't say this with 100% certainty without checking the sources > or a good look at TFM) the PostgreSQL JDBC driver initially does only a > client-side prepare. However, if the PreparedStatement is re-used more than > a certain number of times (five by default?) it switches to server-side > prepared statements. > This is partially true. The driver uses an unnamed prepared statement on the server. > This has actually caused a bunch of performance complaints on the jdbc list, > because the query plan may change at that switch-over point, since with a > server-side prepared statement Pg no longer has a specific value for each > parameter and may pick a more generic plan. This is a limitation of the server, not the driver