Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 73225 invoked from network); 14 Jan 2010 12:07:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jan 2010 12:07:11 -0000 Received: (qmail 73973 invoked by uid 500); 14 Jan 2010 12:07:10 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 73915 invoked by uid 500); 14 Jan 2010 12:07:10 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 73907 invoked by uid 99); 14 Jan 2010 12:07:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 12:07:10 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [192.18.6.24] (HELO gmp-eb-inf-2.sun.com) (192.18.6.24) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 12:07:01 +0000 Received: from fe-emea-09.sun.com (gmp-eb-lb-1-fe1.eu.sun.com [192.18.6.7] (may be forged)) by gmp-eb-inf-2.sun.com (8.13.7+Sun/8.12.9) with ESMTP id o0EC6cqg002208 for ; Thu, 14 Jan 2010 12:06:38 GMT MIME-version: 1.0 Received: from conversion-daemon.fe-emea-09.sun.com by fe-emea-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) id <0KW800A00D3F9300@fe-emea-09.sun.com> for derby-user@db.apache.org; Thu, 14 Jan 2010 12:06:18 +0000 (GMT) Received: from localhost ([unknown] [129.159.112.201]) by fe-emea-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) with ESMTPSA id <0KW800DCAKA24E00@fe-emea-09.sun.com> for derby-user@db.apache.org; Thu, 14 Jan 2010 12:06:03 +0000 (GMT) Date: Thu, 14 Jan 2010 13:06:02 +0100 From: "Bernt M. Johnsen" Subject: Re: Streaming Results In-reply-to: <71a64ba61001140317td96295bg9d0271c9837b3377@mail.gmail.com> Sender: Bernt.Johnsen@Sun.COM To: Derby Discussion Message-id: <20100114120602.GC6588@atum01.Norway.Sun.COM> Organization: Sun Microsystems Content-type: multipart/signed; boundary=t0UkRYy7tHLRMCai; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-disposition: inline References: <4B4ECB24.4020607@brattland.no> <20100114090801.GA6588@atum01.Norway.Sun.COM> <4B4EEB87.5070301@brattland.no> <20100114103335.GB6588@atum01.Norway.Sun.COM> <71a64ba61001140317td96295bg9d0271c9837b3377@mail.gmail.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) --t0UkRYy7tHLRMCai Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, >>>>>>>>>>>> Brett Wooldridge wrote (2010-01-14 20:17:35): > Bernt, >=20 > I think the issue is that Derby will materialize the entire ResultSet on = the > client-side before returning it to the user. If the ResultSet is one > million rows, then one million rows will be transferred and materialized = on > the client before the executeQuery() call returns to the user. No. My point is that Derby won't materialize the entire result set on the client side. The driver will usually materialize the number of rows that fits into the 32K communications buffer, and when the buffer is exhausted, it will fetch and materialize another 32K. > Some databases and drivers have the capability to return a streaming > ResultSet, such that rows are only transferred as ResultSet.next() is > called. If the driver is clever, it can keep a bit ahead of the calls to > next() by transferring X number of rows at a time (where X is something m= uch > smaller than a million). >=20 > I do not have personal knowledge of whether Derby supports ResultSet > streaming (which is distinct from streaming datatypes like CLOBs or BLOBs= ). > I just wanted to make sure the distinction in the question was > clear. What you call "ResultSet streaming" is as far is I know the normal behaviour of most JDBC drivers. >=20 > Brett >=20 >=20 > On Thu, Jan 14, 2010 at 7:33 PM, Bernt M. Johnsen = wrote: >=20 > > >>>>>>>>>>>> Stian Brattland wrote (2010-01-14 11:01:43): > > > Hi, > > > > > > Thank you for your quick reply. > > > > > > I will elaborate a little on my question: > > > > > > I often need to retrieve a large amount of data from a remote MySQL > > > database. However, > > > if my application runs with a default heap size, then i will quickly = get > > > some sort of heap space > > > exception. The reason is that the ResultSet containing the retrieved > > > data is too large. What i have > > > done to get around this is to stream the results from the database, a= nd > > > process rows one by one > > > as they are streamed (for instance, storing them in a local database, > > > like Derby). Of course, things > > > are most likely behaving more optimal than only transfering one row a= t a > > > time from the database > > > (yes, some buffers are most likely involved). However, my key point w= as > > > that i do not have to wait > > > for the entire ResultSet to become ready before i can start iterating > > > over the rows. Instead, rows ( > > > be it one or hundred) are retrieved as i iterate over the ResultSet. > > > > > > So, my question is wether the Derby Driver has this ability too? > > > > Yes, that is exactly what the Derby driver (and all other reasonable > > implemented JDBC drivers) will do. The driver will attempt to fill up > > the communication buffer (32K) as long as at least one row fits into > > it. > > > > > > > > Kind regards, > > > Stian Brattland > > > > > > > > > My intention with the question was not really to point out that a the > > > driver needs to retrive > > > results in the most ineffective manner as possible. > > > > > > Bernt M. Johnsen skrev: > > >> Hi, > > >> > > >> Some general remarks (don't remember the exact details of what Derby > > >> actually does with setFetchSize). > > >> > > >> > > >>>>>>>>>>>>>> Stian Brattland wrote (2010-01-14 08:43:32): > > >>>>>>>>>>>>>> > > >>> Hi, > > >>> > > >>> I've got a question regarding results streaming. The J/Connector for > > >>> MySQL supports results streaming, which means > > >>> that you can stream and process rows in a ResultSet one by one. > > >>> Normally, all rows in a ResultSet will be retrived > > >>> before you can process the ResultSet. However, i am curious as to > > >>> wether this "feature" also exists in Derby? > > >>> > > >> > > >> Normally, a JDBC driver will retrieve a suitable number of rows, not > > >> necessarily all, depending on various factors such as row size, numb= er > > >> of rows resulting from the query and communication buffer size. > > >> > > >> > > >>> In MySQL, you would do the following to stream results from the > > >>> database as you iterate through a ResultSet: > > >>> > > >>> stmt =3D conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, > > java.sql.ResultSet.CONCUR_READ_ONLY); > > >>> stmt.setFetchSize(Integer.MIN_VALUE); > > >>> > > >> > > >> setFetchSize is just a hint to the driver, See > > >> > > >> > > http://jscstage.sfbay.sun.com/javase/6/docs/api/java/sql/Statement.html= #setFetchSize(int) > > >> > > >> A well written driver will still try to do thing's optimal, such as > > >> e.g. fill up the communication buffer with rows to reduce the number > > >> of roundtrips, regardless of how low you set the fetchSize. > > >> > > >> And last, why would you like to force the driver to fetch the rows o= ne > > >> by one? The only thing you will get fromthat, is extra overhead. > > >> > > > > -- > > Bernt Marius Johnsen, Staff Engineer > > Database Technology Group, Sun Microsystems, Trondheim, Norway > > > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.4.6 (GNU/Linux) > > > > iD8DBQFLTvL+lFBD9TXBAPARAvlGAJ9zaW2WAFG/97gneqpYZq8IWAkfagCfVEH9 > > 3kGYBcg23Fbt34k9lSiqOjk=3D > > =3DD9VP > > -----END PGP SIGNATURE----- > > > > --=20 Bernt Marius Johnsen, Staff Engineer Database Technology Group, Sun Microsystems, Trondheim, Norway --t0UkRYy7tHLRMCai Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFLTwiqlFBD9TXBAPARAhklAJ9ffRM6EWnuNCaoEBDXKKK7NnUpNACggtMa FEMIusrX5pSF073Qg/6UdCk= =FmcW -----END PGP SIGNATURE----- --t0UkRYy7tHLRMCai--