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 ADD8FD1B17B for ; Fri, 21 May 2004 08:27:43 -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 10832-05 for ; Fri, 21 May 2004 08:27:26 -0300 (ADT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id EC51BD1B1CA for ; Fri, 21 May 2004 08:27:21 -0300 (ADT) Received: (qmail 11654 invoked from network); 21 May 2004 11:27:20 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.36?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 21 May 2004 11:27:20 -0000 Subject: Re: Queries with large ResultSets From: Dave Cramer Reply-To: pg@fastcrypt.com To: Oliver Jowett Cc: Andrea Aime , pgsql-jdbc@postgresql.org, Tom Lane In-Reply-To: <40AD3733.5000905@opencloud.com> References: <40ABD19C.8080109@geophile.com> <200405202022.37646.andrea.aime@aliceposta.it> <40AD3733.5000905@opencloud.com> Content-Type: text/plain Organization: Cramer Consulting Message-Id: <1085138839.1591.26.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Fri, 21 May 2004 07:27:19 -0400 Content-Transfer-Encoding: 7bit X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) 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/148 X-Sequence-Number: 10158 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. Tom ? Dave On Thu, 2004-05-20 at 18:54, Oliver Jowett wrote: > Andrea Aime wrote: > > > Ugh... those limitation are really frightening, this means we cannot fetch > > big quantities of data outside of a transaction... this is a problem with > > application servers like GeoServer that keep a connection pool and > > need to fetch big quantities of data also outside a transaction... any hope > > to see this fixed soon? Is it a driver problem or a server limitation? > > Cursor are implicitly closed at the end of a transaction unless they are > declared WITH HOLD. Declaring a cursor WITH HOLD has an associated cost > on the backend (namely it will copy the cursor's contents at the end of > the transaction). If autocommit is on, you have an implicit transaction > around every query, so it doesn't make sense to use a non-holdable > cursor with autocommit on -- you'd never be able to fetch any results. > > This could be controllable via the JDBC3 resultset holdability methods, > but currently it isn't and all resultsets effectively default to > ResultSet.CLOSE_CURSORS_AT_COMMIT. > > I don't think you want a holdable cursor for this case anyway since the > backend would end up doing a lot of unnecessary copying results around. > If you're accessing big quantities of data, the overhead of an explicit > commit() after you're done with the resultset is going to be > insignificant compared to the cost of actually transferring and handling > that data. Use something like this: > > connection.setAutoCommit(false); > PreparedStatement stmt = connection.prepareStatement("SELECT ...."); > ResultSet rs = stmt.executeQuery(); > while (rs.next()) { > // process data > } > rs.close(); > connection.commit(); > > -O > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match > > > > !DSPAM:40ad3936130991925076984! > > -- Dave Cramer 519 939 0336 ICQ # 14675561