Forcing use of cursor result sets

From: "Sverre H(dot) Huseby" <shh(at)thathost(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Forcing use of cursor result sets
Date: 2003-11-21 20:58:59
Message-ID: 20031121205859.GI2946@thathost.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi, guys!

I'm making a write-up for my PostgreSQL-using friends, and wonder if
anyone could verify the correctness (or opposite) of the following:

---------------------------------------------------------------------
Memory Problems with the PostgreSQL JDBC Driver

For some reason, the official PostgreSQL JDBC caches the entire result
set in a Vector before returning stuff to the caller. For most
applications that may work fine, but for applications that work with
gigantic result sets this may exhaust memory. Recent (2003) versions
of the JDBC driver support "cursor result sets" that only reads a
limited number of rows before returning to the caller. Those cursor
result sets are not the default, though. A couple of constraints must
be fulfilled before they kick into action:

1. The Connection must not be in auto commit mode:

conn.setAutoCommit(false);

2. We must tell the driver (through the Statement object) how many
rows to prefetch, otherwise it will fetch all:

stmt.setFetchSize(32);

3. The statement must be a single SELECT statement. No "batched
queries".

In case you're interested: The code that checks for the magic is in
the function getQueryFragments() in
org.postgresql.jdbc1.AbstractJdbc1Statement, and it looks like this as
of this writing (2003-11-21):

if (fetchSize > 0 && !connection.getAutoCommit() && isSingleSelect())
return transformToCursorFetch();
---------------------------------------------------------------------

Thanks for your help.

Sverre.

--
shh(at)thathost(dot)com
http://shh.thathost.com/

Browse pgsql-jdbc by date

  From Date Subject
Next Message guan zhifan 2003-11-23 03:50:03 forhelp
Previous Message Kris Jurka 2003-11-21 11:18:07 Re: Avoiding Statement.cancel() races