This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

query regarding getFetchSize

 
anagha patankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On ne of the websites - it is written to improve performance one should set the "fetchSize" of the prepared statement and ResultSet.

1 >Lets say if I set a fetch size of 10 and my query returns 20 records - are all records held in memory or only 10 are in memory and when I iterate to the 11th record - then the remaining are fetched from database ?

Regards,
-anagha
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anagha,
That would result in two trips to the database. Sometimes tuning the fetch size is advisable as it results in less network trips.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot to mention: I would advise against making the fetch size smaller than the default.
 
anagha patankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne for your replies .

So when you say there will be two trips to the database :
1 >Where is the resultset stored - is that stored in SGA ( In case of Oracle )
2 >If we are using a resultset - then believe all the data is anyway on the server side ( not like disconnected rowset )

So are you saying that after query execution ( results obtained = 20 rows & fetchSize = 10 ) that 20 rows will be stored in SGA

So where are the first 10 records read / picked from

What happens when we access the 11th record ?

Too many questions and too much confusion at my end .

Any answers will be greatly appreciated .

Regards,
-anagha
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about what is stored in SGA. That is within Oracle, so I don't need to think about it as an app developer.

> If we are using a resultset - then believe all the data is anyway on the
> server side ( not like disconnected rowset )
It's on the client side too. When you call rs.next(), the data is transfered to the client side. We wouldn't want this to happen on every call to rs.next() so fetch size tells the driver how often to go to the server to get more data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic