pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marc Herbert <Marc.Herbert@continuent.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Limit vs setMaxRows issue
Date: Tue, 11 Jul 2006 14:14:58 +0200
Message-ID: <khjsll8xrr1.fsf@meije.emic.fr> (raw)
References: <44990D57.9070506@sebster.com>
	<Pine.BSO.4.63.0606211055020.7242@leary2.csoft.net>
	<34158.216.41.12.254.1150906222.squirrel@webmail.webopticon.org>
	<11362.1150908394@sss.pgh.pa.us>
	<khjd5cd4zcm.fsf@meije.emic.fr>
	<44B34751.7010704@opencloud.com>
	<khjr70szd30.fsf@meije.emic.fr>
	<44B38164.1040606@opencloud.com>

Oliver Jowett <oliver@opencloud.com> writes:

> Marc Herbert wrote:
>> Oliver Jowett <oliver@opencloud.com> 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 <code>prepareStatement</code> 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
<http://www.postgresql.org/docs/8.1/interactive/sql-prepare.html;
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.





view thread (23+ messages)  latest in thread

Message-ID: <khjsll8xrr1.fsf@meije.emic.fr>
Permalink:  ../khjsll8xrr1.fsf@meije.emic.fr/
Also on:    postgresql.org/message-id/khjsll8xrr1.fsf@meije.emic.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: Marc.Herbert@continuent.com
  Subject: Re: Limit vs setMaxRows issue
  In-Reply-To: <khjsll8xrr1.fsf@meije.emic.fr>
  References: <44990D57.9070506@sebster.com> <Pine.BSO.4.63.0606211055020.7242@leary2.csoft.net> <34158.216.41.12.254.1150906222.squirrel@webmail.webopticon.org> <11362.1150908394@sss.pgh.pa.us> <khjd5cd4zcm.fsf@meije.emic.fr> <44B34751.7010704@opencloud.com> <khjr70szd30.fsf@meije.emic.fr> <44B38164.1040606@opencloud.com> <khjsll8xrr1.fsf@meije.emic.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox