Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 389226331DE; Mon, 9 Mar 2009 18:40:54 -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 15805-09; Mon, 9 Mar 2009 18:40:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 84FCC6323D4; Mon, 9 Mar 2009 18:40:47 -0300 (ADT) Received: from 219-89-241-75.adsl.xtra.co.nz ([219.89.241.75] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1LgnDA-0005zo-U8; Tue, 10 Mar 2009 10:40:37 +1300 Message-ID: <49B58CCA.8060308@opencloud.com> Date: Tue, 10 Mar 2009 10:40:26 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: Scott Carey CC: Guillaume Smet , Guillaume Cottenceau , Mario Splivalo , "pgsql-performance@postgresql.org" , "pgsql-jdbc@postgresql.org" Subject: Re: [PERFORM] Query much slower when run from postgres function References: In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 200903/39 X-Sequence-Number: 19369 Scott Carey wrote: > > 1. And how do you do that from JDBC? There is no standard concept of > ‘unnamed’ prepared statements in most database APIs, and if there > were the behavior would be db specific. Telling PG to plan after > binding should be more flexible than unnamed prepared statements — > or at least more transparent to standard APIs. E.g. SET > plan_prepared_postbind=’true’. I've suggested that as a protocol-level addition in the past, but it would mean a new protocol version. The named vs. unnamed statement behaviour was an attempt to crowbar it into the protocol without requiring a version change. If it's really a planner behaviour thing, maybe it does belong at the SET level, but I believe that there's usually an aversion to having to SET anything per query to get reasonable plans. > 2. How do you use those on a granularity other than global from jdbc? prepareThreshold=N (as part of a connection URL), org.postgresql.PGConnection.setPrepareThreshold() (connection-level granularity), org.postgresql.PGStatement.setPrepareThreshold() (statement-level granularity). See the driver docs. > ( — I tried setting max_prepared_transactions to 0 but this > didn’t seem to work either, and it would be global if it did). max_prepared_transactions is to do with two-phase commit, not prepared statements. > In the end, we had to write our own client side code to deal with sql > injection safely and avoid jdbc prepared statements to get acceptable > performance in many cases (all cases involving partitioned tables, a few > others). At least dollar-quotes are powerful and useful for dealing > with this. Since the most important benefit of prepared statements is > code clarity and sql injection protection, its sad to see weakness in > control/configuration over prepared statement behavior at the parse/plan > level get in the way of using them for those benefits. It's unfortunate that ended up doing this, because it >is< all configurable on the JDBC side. Did you ask on pgsql-jdbc? -O