

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
24 messages in org.postgresql.pgsql-jdbcLimit vs setMaxRows issue| From | Sent On | Attachments |
|---|---|---|
| Sebastiaan van Erk | Jun 21, 2006 2:11 am | |
| Dave Cramer | Jun 21, 2006 7:56 am | |
| Sebastiaan van Erk | Jun 21, 2006 8:48 am | |
| Kris Jurka | Jun 21, 2006 8:59 am | |
| A.M. | Jun 21, 2006 9:09 am | |
| Tom Lane | Jun 21, 2006 9:46 am | |
| Oliver Jowett | Jun 21, 2006 3:52 pm | |
| Sebastiaan van Erk | Jun 22, 2006 1:35 am | |
| Mark Lewis | Jun 22, 2006 9:15 am | |
| David Wall | Jun 22, 2006 9:36 am | |
| Sebastiaan van Erk | Jun 22, 2006 1:13 pm | |
| Marc Herbert | Jul 10, 2006 1:50 am | |
| Marc Herbert | Jul 10, 2006 1:59 am | |
| Marc Herbert | Jul 10, 2006 2:05 am | |
| Oliver Jowett | Jul 10, 2006 11:32 pm | |
| Oliver Jowett | Jul 10, 2006 11:37 pm | |
| Marc Herbert | Jul 11, 2006 2:48 am | |
| Marc Herbert | Jul 11, 2006 3:00 am | |
| Oliver Jowett | Jul 11, 2006 3:45 am | |
| Marc Herbert | Jul 11, 2006 5:14 am | |
| Oliver Jowett | Jul 11, 2006 10:01 pm | |
| Marc Herbert | Jul 12, 2006 3:22 am | |
| Markus Schaber | Jul 12, 2006 3:59 am | |
| Marc Herbert | Jul 20, 2006 11:52 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Limit vs setMaxRows issue | Actions... |
|---|---|---|
| From: | Sebastiaan van Erk (sebs...@sebster.com) | |
| Date: | Jun 21, 2006 2:11:28 am | |
| List: | org.postgresql.pgsql-jdbc | |
Hi,
When using the ps.setMaxRows() call on PreparedStatement, the jdbc driver sets the row limit via the "raw" postgres protocol. However, in the words of Tom Lane, "the row limit in the protocol only says how many rows to deliver in the first batch. The presumption is that you'll eventually grab the rest, and so the query is planned on that basis."
What this means that when we do the following query:
select action_id from actions order by action_id
with a ps.setMaxRows(100), it takes about 1.8 seconds for the query to complete. However, if we do the following query:
select action_id from actions order by action_id limit 100
without any ps.setMaxRows() the query only takes 0.156 seconds. This is more than a factor of 10 faster.
I'm not 100% sure of what JDBC says about setMaxRows (it's kind of ambiguous in the java doc, as usual), but as far as I can tell, if you call setMaxRows on the prepared statement there is no way in to ever retrieve more than that number of rows. If this is indeed the case, it seems to me that currently there is a mismatch between the JDBC api and the postgresql api, and JDBC should somehow tell postgres that this is a hard limit and it should not plan for a second batch.
Therefore, my question is: is this a bug? It is not feasable for me to add LIMIT clauses to all the SQL queries in my code, so if this IS a bug, I hope it can be fixed. If it is NOT a bug, is there an alternative workaround that does not involve changing all of my sql statements?
Thanks in advance, Sebastiaan







