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 796BC9FB2ED for ; Tue, 11 Jul 2006 09:15:21 -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 37010-06 for ; Tue, 11 Jul 2006 09:15:12 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 837889FB2C2 for ; Tue, 11 Jul 2006 09:15:12 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1G0H8q-0001ye-UI for pgsql-jdbc@postgresql.org; Tue, 11 Jul 2006 14:15:04 +0200 Received: from 83.145.96.118 ([83.145.96.118]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 11 Jul 2006 14:15:04 +0200 Received: from Marc.Herbert by 83.145.96.118 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 11 Jul 2006 14:15:04 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Marc Herbert Subject: Re: Limit vs setMaxRows issue Date: Tue, 11 Jul 2006 14:14:58 +0200 Lines: 55 Message-ID: References: <44990D57.9070506@sebster.com> <34158.216.41.12.254.1150906222.squirrel@webmail.webopticon.org> <11362.1150908394@sss.pgh.pa.us> <44B34751.7010704@opencloud.com> <44B38164.1040606@opencloud.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 83.145.96.118 User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Jumbo Shrimp, linux) Cancel-Lock: sha1:8NUkcQVKR0s9cmyRjzTWWHeHgk4= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/34 X-Sequence-Number: 15460 Oliver Jowett writes: > Marc Herbert wrote: >> Oliver Jowett writes: > >>> the query is parsed and planned immediately before execution. >> Hum, interesting. Looks like "lazy prepared" statement, no >> pre-compilation? If you delay parsing & planning then of course you >> would not need to go back in time to add late >> optimizations... > > I don't know what you mean by "lazy prepared" statements. We give the > statement to the server for parsing and planning at the point when we > know both the query and the parameter types -- which, because of the > JDBC API design, means just before execution. OK thanks, now I think I got it: it seems like the JDBC API does not assume you need parameter types to plan the query. Connection.preparedStatement() * If the driver supports precompilation, * the method prepareStatement will send * the statement to the database for precompilation. No word about parameter types. If you do not need the datatypes, then you can send/plan the query way earlier (not "lazy"), at PreparedStatement object construction time. I should have noticed this issue from here Looks like we have an API mismatch here. Is this parameter types issue specific to PostgreSQL, or is just the JDBC API badly designed on this point? Another approach could be for the server to infer the types from the query string? If not 100% reliably, then in an optimistic way? > We retain the parse/plan results on the server side when it looks > like the statement will be reused (using a simple "how many times > has this statement already been reused?" metric), otherwise we > reparse/replan on each execution. Could this be compatible with any setMaxRows() optimization? I guess yes, provided the maxRows parameter is considered in preparedstatement matching, just like datatypes seem to be... Maybe this is already the case for non-JDBC PREPARE + LIMIT? Thanks again for all these answers.