X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E516D9FB2E2 for ; Tue, 11 Jul 2006 00:38:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 60321-01 for ; Tue, 11 Jul 2006 00:38:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by postgresql.org (Postfix) with ESMTP id CE73C9FB2E3 for ; Tue, 11 Jul 2006 00:38:05 -0300 (ADT) Received: from sony.opencloud.co.nz ([192.168.0.41]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1G094W-0004LR-PL; Tue, 11 Jul 2006 15:38:04 +1200 Message-ID: <44B34751.7010704@opencloud.com> Date: Tue, 11 Jul 2006 15:38:09 +0900 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.8 (X11/20060502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Marc Herbert CC: pgsql-jdbc@postgresql.org Subject: Re: Limit vs setMaxRows issue References: <44990D57.9070506@sebster.com> <34158.216.41.12.254.1150906222.squirrel@webmail.webopticon.org> <11362.1150908394@sss.pgh.pa.us> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/30 X-Sequence-Number: 15456 Marc Herbert wrote: > Tom Lane writes: > > >>No, it would take a protocol change to add such a thing out-of-line >>(that is, not as a LIMIT clause in the query text). The reason is that >>the planning is done at PARSE time, or at the latest BIND time. The >>row limit field in the EXECUTE message comes far too late to affect the >>query plan. > > > > If planning is done at time of creation of the PreparedStatement > object (reminder: the example given above has no parameters), then the > setMaxRows() call will come too late whatever is the protocol change. > I mean: no protocol change can go back in time and "optimize" by not > doing useless work already done. > > Thanks in advance for pointing out my mistake(s) here. We do not special-case the no-parameters case, so it's handled just like all the other cases: the query is parsed and planned immediately before execution. We also avoid an extra round-trip by doing it at that point. If you're interested in the details of this, the driver source code is really your best reference.. -O