From: Tom Lane <tgl@sss.pgh.pa.us>
To: pg@fastcrypt.com
Cc: Oliver Jowett <oliver@opencloud.com>
Cc: Andrea Aime <andrea.aime@aliceposta.it>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Queries with large ResultSets
Date: Fri, 21 May 2004 10:30:37 -0400
Message-ID: <28597.1085149837@sss.pgh.pa.us> (raw)
In-Reply-To: <1085138839.1591.26.camel@localhost.localdomain>
References: <40ABD19C.8080109@geophile.com>
<Pine.BSO.4.56.0405201057110.11233@leary.csoft.net>
<200405202022.37646.andrea.aime@aliceposta.it>
<40AD3733.5000905@opencloud.com>
<1085138839.1591.26.camel@localhost.localdomain>
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
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: tgl@sss.pgh.pa.us, pg@fastcrypt.com, oliver@opencloud.com, andrea.aime@aliceposta.it
Subject: Re: Queries with large ResultSets
In-Reply-To: <28597.1085149837@sss.pgh.pa.us>
References: <40ABD19C.8080109@geophile.com> <Pine.BSO.4.56.0405201057110.11233@leary.csoft.net> <200405202022.37646.andrea.aime@aliceposta.it> <40AD3733.5000905@opencloud.com> <1085138839.1591.26.camel@localhost.localdomain> <28597.1085149837@sss.pgh.pa.us>
* 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