24 messages in org.postgresql.pgsql-jdbcRe: Limit vs setMaxRows issue
FromSent OnAttachments
Sebastiaan van ErkJun 21, 2006 2:11 am 
Dave CramerJun 21, 2006 7:56 am 
Sebastiaan van ErkJun 21, 2006 8:48 am 
Kris JurkaJun 21, 2006 8:59 am 
A.M.Jun 21, 2006 9:09 am 
Tom LaneJun 21, 2006 9:46 am 
Oliver JowettJun 21, 2006 3:52 pm 
Sebastiaan van ErkJun 22, 2006 1:35 am 
Mark LewisJun 22, 2006 9:15 am 
David WallJun 22, 2006 9:36 am 
Sebastiaan van ErkJun 22, 2006 1:13 pm 
Marc HerbertJul 10, 2006 1:50 am 
Marc HerbertJul 10, 2006 1:59 am 
Marc HerbertJul 10, 2006 2:05 am 
Oliver JowettJul 10, 2006 11:32 pm 
Oliver JowettJul 10, 2006 11:37 pm 
Marc HerbertJul 11, 2006 2:48 am 
Marc HerbertJul 11, 2006 3:00 am 
Oliver JowettJul 11, 2006 3:45 am 
Marc HerbertJul 11, 2006 5:14 am 
Oliver JowettJul 11, 2006 10:01 pm 
Marc HerbertJul 12, 2006 3:22 am 
Markus SchaberJul 12, 2006 3:59 am 
Marc HerbertJul 20, 2006 11:52 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Limit vs setMaxRows issueActions...
From:Marc Herbert (Marc@continuent.com)
Date:Jul 11, 2006 5:14:35 am
List:org.postgresql.pgsql-jdbc

Oliver Jowett <oli@opencloud.com> writes:

Marc Herbert wrote:

Oliver Jowett <oli@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.