• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.getRow is slow for large ResultSet

 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody know why .geRow is so slow for large ResultSets. I return a result set in my servlet. I do ResultSet.last() then ResultSet.getRow() to get how many rows were returned. The larger the result set the longer it takes getRow() to return a value...This doesn't make any sense to me. Does anybody know where I can look at the code for that method? Maybe that will explain what the heck is going on...
 
Paul Clapham
Sheriff
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course it does. When you say "Find the last row", the driver must read in all the rows and store them in memory. Naturally it takes ten times as long to load 1000 rows as it does to load 100 rows.

But you should really stop wanting to know how many rows there are going to be. Just read them yourself, which you were going to do anyway, and when you have read them all you will then know how many rows there were.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to actually read all the rows. I just need to know how many there are so that I can calculate the number of pages I will have, and then display them in selected sets of 10, 20, 30, or whatever I allow the user to choose. I'm currently looking into using row_number() so that I only return the results that I need for a given page. That way I'm only getting result sets of 10, or 20 etc rows of data.
 
Jeff Rummings
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to actually read all the rows. I just need to know how many there are


If you don't need the data, you could do a select count:

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arman Sharif:


If you don't need the data, you could do a select count:



That will get you the number of rows with a widget_id != null. If you really want the total number of rows, you should use



That will also execute even faster.

Of course you can also add a WHERE clause to that statement.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I really want to add a Count() to it...I just have to figure that part out. I have an enormous statement...and I just need to figure out if I can do it.

I'll report back if I have problems...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic