Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V4Eiu-0005KM-P9 for pgsql-jdbc@arkaria.postgresql.org; Tue, 30 Jul 2013 18:32:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V4Eiu-0000WM-85 for pgsql-jdbc@arkaria.postgresql.org; Tue, 30 Jul 2013 18:32:40 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V4Eis-0000Uc-Nq for pgsql-jdbc@postgresql.org; Tue, 30 Jul 2013 18:32:38 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V4Eip-0004us-Kr for pgsql-jdbc@postgresql.org; Tue, 30 Jul 2013 18:32:38 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1V4Eio-0004FV-O8 for pgsql-jdbc@postgresql.org; Tue, 30 Jul 2013 11:32:34 -0700 Date: Tue, 30 Jul 2013 11:32:34 -0700 (PDT) From: jwollman To: pgsql-jdbc@postgresql.org Message-ID: <1375209154731-5765663.post@n5.nabble.com> In-Reply-To: References: Subject: Re: Slow statement when using JDBC MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 4.5 (++++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org There was no end to this thread so, as I have just run into this problem, I thought I post. I can validate Yazen problem using Prepared statements as not a JDBC problem but actually a problem that exists in pre-9.2 versions of Postgres. I work for a company that provides a product with an embedded database. We currently have Postgres version 9.0.3 and have run into the exact same problem: Prepared Statements with Bind Variables run significantly slower than statements without Bind Variables either via JDBC or in database itself. I took the slow running Prepared Statement with Bind Variables from our application and replicated the same exact problem by running it against same version 9.0.3 of Postgres in pg_Admin using Prepare foo as ; Execute foo ('xxxx', 'yyyy'); The query took 40,000ms to run. (I also took same query and resolved bind variables to actual values and ran in the same manner as a prepared statement. The query took 111ms to run.) I also took the same query with Bind Variables and ran as Prepared Statement using the same dataset but on version 9.2.4 of Postgres. The query took 77ms and used a reasonable explain plan. Conclusion: this appears to be a database problem due to odd explain plan for Prepared Statements with Bind Variables. Kevin Grittner's comment in this thread seems to be a good explanation. Good news: that this was validated as a bug and was fixed by Tom Lane in version 9.2 of Postgres. See: http://stackoverflow.com/questions/12368338/how-to-make-postgresql-optimizer-to-build-execution-plan-after-binding-parameter Thanks, Jon Wollman Portfolio Data Architect, Rapid7 -- View this message in context: http://postgresql.1045698.n5.nabble.com/Slow-statement-when-using-JDBC-tp3368379p5765663.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com. -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc