From: Oliver Jowett <oliver@opencloud.com>
To: Andrea Aime <andrea.aime@aliceposta.it>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Queries with large ResultSets
Date: Fri, 21 May 2004 10:54:43 +1200
Message-ID: <40AD3733.5000905@opencloud.com> (raw)
In-Reply-To: <200405202022.37646.andrea.aime@aliceposta.it>
References: <40ABD19C.8080109@geophile.com>
<Pine.BSO.4.56.0405201057110.11233@leary.csoft.net>
<200405202022.37646.andrea.aime@aliceposta.it>
Andrea Aime wrote:
> Ugh... those limitation are really frightening, this means we cannot fetch
> big quantities of data outside of a transaction... this is a problem with
> application servers like GeoServer that keep a connection pool and
> need to fetch big quantities of data also outside a transaction... any hope
> to see this fixed soon? Is it a driver problem or a server limitation?
Cursor are implicitly closed at the end of a transaction unless they are
declared WITH HOLD. Declaring a cursor WITH HOLD has an associated cost
on the backend (namely it will copy the cursor's contents at the end of
the transaction). If autocommit is on, you have an implicit transaction
around every query, so it doesn't make sense to use a non-holdable
cursor with autocommit on -- you'd never be able to fetch any results.
This could be controllable via the JDBC3 resultset holdability methods,
but currently it isn't and all resultsets effectively default to
ResultSet.CLOSE_CURSORS_AT_COMMIT.
I don't think you want a holdable cursor for this case anyway since the
backend would end up doing a lot of unnecessary copying results around.
If you're accessing big quantities of data, the overhead of an explicit
commit() after you're done with the resultset is going to be
insignificant compared to the cost of actually transferring and handling
that data. Use something like this:
connection.setAutoCommit(false);
PreparedStatement stmt = connection.prepareStatement("SELECT ....");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
// process data
}
rs.close();
connection.commit();
-O
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: oliver@opencloud.com, andrea.aime@aliceposta.it
Subject: Re: Queries with large ResultSets
In-Reply-To: <40AD3733.5000905@opencloud.com>
References: <40ABD19C.8080109@geophile.com> <Pine.BSO.4.56.0405201057110.11233@leary.csoft.net> <200405202022.37646.andrea.aime@aliceposta.it> <40AD3733.5000905@opencloud.com>
* 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