X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id D8D68D1CCA5 for ; Fri, 21 May 2004 11:31:01 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 82496-05 for ; Fri, 21 May 2004 11:30:45 -0300 (ADT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 5CE50D1B18A for ; Fri, 21 May 2004 11:30:41 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i4LEUcvt028598; Fri, 21 May 2004 10:30:38 -0400 (EDT) To: pg@fastcrypt.com Cc: Oliver Jowett , Andrea Aime , pgsql-jdbc@postgresql.org Subject: Re: Queries with large ResultSets In-reply-to: <1085138839.1591.26.camel@localhost.localdomain> References: <40ABD19C.8080109@geophile.com> <200405202022.37646.andrea.aime@aliceposta.it> <40AD3733.5000905@opencloud.com> <1085138839.1591.26.camel@localhost.localdomain> Comments: In-reply-to Dave Cramer message dated "Fri, 21 May 2004 07:27:19 -0400" Date: Fri, 21 May 2004 10:30:37 -0400 Message-ID: <28597.1085149837@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/151 X-Sequence-Number: 10161 Dave Cramer 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