my dog learned polymorphism*
The moose likes JDBC and the fly likes Performance issue if I do not retrieve the rest of result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Performance issue if I do not retrieve the rest of result set" Watch "Performance issue if I do not retrieve the rest of result set" New topic
Author

Performance issue if I do not retrieve the rest of result set

liang gu
Ranch Hand

Joined: Nov 05, 2001
Posts: 89
My result set is a huge list. And I want to reduce the data transfered between the Oracle database and my application. If I only retrieve the first few rows from the result set, and then just close the result set. Does all the data rows from the result set already transfered from Oracle to my application regardless that I didn't read these result set? Or is it the other way around, that only the data rows that I read, has actually transfered from Oracle to my application?
And does the Oracle database server already generate the full result set in its' memory before I read a single row of result set? Thanks.
Liang
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

For non-scrollable, Oracle will fetch into memory the number of records specified in the fetch size parameter. Once you need more records, the old records are discarded and the number of new records specified by the fetch size are loaded into memory. In general, A higher fetch size means more memory usage, but less calls to the database and vice versa. So at any time, with the ResultSet open or closed, the maximum number of records in memory is the number specified in the fetch size.
BEWARE!! Scrollable resultsets work a little differently. They generally work the same as non-scrollable except when you need more records, the old records are NOT discarded and the number of new records specified by the fetch size are loaded into memory. So at any time, with the ResultSet open, the maximum number of records in memory is the number of records you have iterated through rounded up to a multiple of the fetch size.
Not exactly sure what happens on Oracle, but I'm pretty sure they just have pointers ( in the general sense ) to the matched rows, the current one being the cursor.
Jamie
[ November 29, 2002: Message edited by: Jamie Robertson ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Performance issue if I do not retrieve the rest of result set
 
Similar Threads
Looking for a better data-transfer mechanism
J2EE spec implementation
How to use streaming when query the database opposed to retrieve all data at once in resultset.
Not serializable Exception or No Data to read from socket
Complicated SQL query help