Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id AE4BA634BF9 for ; Tue, 14 Apr 2009 15:02:29 -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 84456-01 for ; Tue, 14 Apr 2009 15:02:23 -0300 (ADT) Received: from mx3.hub.org (mx3.hub.org [206.223.169.73]) by mail.postgresql.org (Postfix) with ESMTP id 5E833634B44 for ; Tue, 14 Apr 2009 14:58:44 -0300 (ADT) X-Greylist: delayed 00:36:19.31481 by SQLgrey-1.7.6 Received: from mail.kickstone.com (smtp.kickstone.com [87.194.183.70]) by mx3.hub.org (Postfix) with ESMTP id DB1AB37B4C4 for ; Tue, 14 Apr 2009 14:58:43 -0300 (ADT) Received: from host212-183-132-78.uk.access.vodafone.net ([212.183.132.78]:22787 helo=[10.114.132.120]) by mail.kickstone.com with esmtpa (Exim 4.69) (envelope-from ) id 1LtmHq-0007EC-RE; Tue, 14 Apr 2009 18:19:08 +0100 Message-ID: <49E4C586.4070107@kickstone.com> Date: Tue, 14 Apr 2009 18:19:02 +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=1.117 tagged_above=0 required=5 tests=RCVD_IN_SORBS_WEB=1.117 X-Spam-Level: * X-Archive-Number: 200904/51 X-Sequence-Number: 19498 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. > > I'm not sure why it would be there would be an extra round trip? The parse is done anyway, the only extra round trip would be if you did a describe (which admittedly i'm looking into optionally doing for binary transfers) or if you didn't use the preparedStatement to do any queries which is i'd imagine is rare. Maybe i've missed something? >> Has any one looked into moving it? >> > > Why would you want to move it? > > To me it would be cleaner, it looks like the current driver was written prior to v3 of the protocol where only simple queries are used and everything is transmitted as text. The extended protocol stuff has been bolted subsequently to the execute part of the driver rather than doing it when the query is prepared... btw, i have nothing but respect for the writers after doing some work on the another driver some years ago. Also, in fairness i've done a lot of work with the oracle stuff vwhich create portals (cursors) and prepare the statement before the execution and this makes more sense to me. Also, with regard to extra network traffic and latency i'm not suggesting changing the way normal statements are used, only PreparedStatements. This to me fits in more with the way the JDBC spec is worded and i'd guess the more usual use case of statements - Statement for quick and dirty one off queries, PreparedStatement for more complicated/multiple use queries. JOHN