Re: Queries with large ResultSets - Mailing list pgsql-jdbc

From Tom Lane
Subject Re: Queries with large ResultSets
Date
Msg-id 28597.1085149837@sss.pgh.pa.us
Whole thread Raw
In response to Re: Queries with large ResultSets  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-jdbc
Dave Cramer <pg@fastcrypt.com> writes:
> There's some confusion as to whether a cursor is materialized even
> inside a transaction. It could be that complicated queries will be
> stored on the disk too.

It depends on the query and on the cursor options.

If you don't say SCROLL nor WITH HOLD then the result isn't materialized
anywhere, it's just computed and delivered incrementally in response to
FETCH commands.

If you specify SCROLL and the query plan isn't one that's amenable to
being run backwards, then we materialize the result (ie, save aside each
row the first time it is read from the underlying query) so that we can
support FETCH BACKWARD.  By and large, only the simplest seqscan or
indexscan plans (no joins, aggregates, etc) are capable of being run
backwards and so can handle SCROLL without overhead.  You can use
"EXPLAIN DECLARE CURSOR" to see whether a particular query can do this
--- look at whether a Materialize node gets stuck atop the plan when
you add SCROLL.

If you specify WITH HOLD and don't close the cursor before transaction
end, then at transaction end the result is materialized: we read the
entire query output (including any rows you already read) and save it
aside to support future FETCHes.

            regards, tom lane

pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: internal type cache, and getUDT implementation
Next
From: Kris Jurka
Date:
Subject: Re: Driver JDBC3 build 213 for postgreSQL 7.4