Re: Queries with large ResultSets

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pg(at)fastcrypt(dot)com
Cc: Oliver Jowett <oliver(at)opencloud(dot)com>, Andrea Aime <andrea(dot)aime(at)aliceposta(dot)it>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Queries with large ResultSets
Date: 2004-05-21 14:30:37
Message-ID: 28597.1085149837@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Dave Cramer <pg(at)fastcrypt(dot)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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2004-05-21 17:15:30 Re: Driver JDBC3 build 213 for postgreSQL 7.4
Previous Message Dave Cramer 2004-05-21 13:37:43 internal type cache, and getUDT implementation