X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6161DD1B193 for ; Tue, 18 May 2004 21:50:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 65444-06 for ; Tue, 18 May 2004 21:50:33 -0300 (ADT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 93DBED1B1F9 for ; Tue, 18 May 2004 21:50:29 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1BQFHw-0003Ts-00; Wed, 19 May 2004 12:50:29 +1200 Message-ID: <40AAAF52.9040501@opencloud.com> Date: Wed, 19 May 2004 12:50:26 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Jurka Cc: "pgsql-jdbc@postgresql.org" , tgl@sss.pgh.pa.us Subject: Re: v3proto Parse/Bind and the query planner References: <40A84236.6070809@opencloud.com> <40AAA131.3010602@opencloud.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200405/118 X-Sequence-Number: 10128 Kris Jurka wrote: > > On Wed, 19 May 2004, Oliver Jowett wrote: > > >>Instead, how about something like: >> >> - For named statements, plan at Parse time always. >> - For unnamed statements, plan at Bind time always. >> >>The assumption here is that if the client is using the unnamed >>statement, it's unlikely that it will be repeatedly reusing that >>statement with different parameter values so there is little benefit to >>preserving the query plan at the cost of being unable to plan for >>specific parameter values. If the client is using named statements, >>there's no change in behaviour from the current approach, so presumably >>the client knows what it's doing! :) > > > I was under the impression that the query protocol would Parse once and > then Bind/Execute for each execution of a statement. Yes. > If that's true we > can't use the unnamed portal because it can be destroyed if a > multithreaded app is using two Statements simultaneously. The lock on > pgstream will be given up between executions of a statement. By default we re-Parse on each subsequent execution. The Parse is only skipped if there is a named statement corresponding to the query being executed (i.e. we previously sent a named Parse and got a corresponding ParseComplete back). So there's no threading issue, just the cost (hopefully small if planning is not being done) of re-Parsing the statement on each execution. This is already in my v3 changes. The named-vs-unnamed distinction is controlled by a query flag (QUERY_ONESHOT) rather than by whether the query is parameterized or not -- it'll support unnamed statements that have parameters with no changes. Currently QUERY_ONESHOT is only passed when executing queries via the direct-execution Statement interface, but it'd easy to hook up to the state of the useServerPrepare flag for the PreparedStatement case. -O