Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D5418633BD7 for ; Tue, 14 Apr 2009 17:29:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 01014-04 for ; Tue, 14 Apr 2009 17:29:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.kickstone.com (smtp.kickstone.com [87.194.183.70]) by mail.postgresql.org (Postfix) with ESMTP id 788D1633B56 for ; Tue, 14 Apr 2009 17:29:08 -0300 (ADT) Received: from [192.168.2.202] (port=49596) by mail.kickstone.com with esmtpa (Exim 4.69) (envelope-from ) id 1LtpFf-0007el-23; Tue, 14 Apr 2009 21:29:04 +0100 Message-ID: <49E4F20C.6040900@kickstone.com> Date: Tue, 14 Apr 2009 21:29:00 +0100 From: John Lister User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Oliver Jowett CC: pgsql-jdbc@postgresql.org Subject: Re: Query preparation References: <49E4A6FA.7050407@kickstone.com> <49E4AEAC.5000700@opencloud.com> In-Reply-To: <49E4AEAC.5000700@opencloud.com> 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: 200904/52 X-Sequence-Number: 19499 Oliver Jowett wrote: > John Lister wrote: > >> Hi, i was wondering if there is any reason why the query preparation is >> done when the query is executed instead of when the preparedStatement is >> created. >> > > It would be an extra network round-trip on every query, and there's no > requirement to prepare it early. > Just going through the code again and please correct me if i'm wrong, but at the moment there is unnecessary network traffic/latency. Assuming a PreparedStatement, every time execute is called, sendParse and sendDescribePortal are called (the former checks if a server side prepared statement has been created and aborts if so). Admittedly sendParse is only called as many times as setPrepareThreshold is set to (which admittedly may be as low as 1) Apart from the use of unnamed statements/portals within a multi threaded environment which complicates things with parsing, i would have thought you could get away with calling describe(portal) just once. I appreciate that it would need a lot of refactoring to move things around, but are there any objections? Also, i don't know how many server side prepared statements/portals postgresql supports (hopefully memory limited) but would it also not make more sense to make all preparedStatements actually be server side preparedStatements. I can't see what overhead this would add apart from named statements/portals I'd be happy to look into this if there was support... Thanks