Quote:
you didn't mention: the JDBC statement
Your right...I did not see that this is actually on the Statement object, not the Connection. That is a big difference.
Quote:
Sybase doesn't support LIMIT, so I'm guessing that the query is actually for the first (FIRSTROW+MAXROWS) rows, then the result set is scrolled past the first FIRSTROW rows. So the query is returning more data, but the driver never fetches it from the server (which is why it's not taking any more time).
I'm not certain that this is how it works, I'm inferring this from a reasonable about of code perusal.
That seems almost correct. I finally got smart and did a valid integration test with JUnit and Sybase to prove how this works. I used a table with almost 2 million records in it so I can be assured that if it was bringing back all the results I would just hopelessly run out of memory right away.
With Sybase it must be using the setMaxRows() on the Statement to return the amount of records needed to bring back the correct number of paginated results. I know this because the query string is not being manipulated and I can tell from the memory usage and speed that only a small amount of records are being returned. However as I ask for more pages of data (more records) the memory starts to increase and the speed decreases.
So if I need rows 100 - 115 then it would return 115 records from the database, but then return 15 records from the Hibernate call. So it does continue to bring back more results each time from the database and then Hibernate paginates those results.
This is actually as close to perfect as we can get with Sybase and is very cool. I just have to make sure I do not give the users any kind of last page button :) !
Thank you for your help!
Once I recognized it is not on the connection things finally clicked. Like many developers the whole database JDBC connection mechanism has always been abstracted away from me, even before Hibernate when I was using a custom inhouse Connection wrapper. Now that performance is a really big deal at my current job I am trying to learn what is happening at the lowest level so I do not take things at face value. I do wish it was documented somewhere on what is really happening under the covers for each dialect, but I do feel confident in my testing that I could infer what is happening.
I do have the source code with Hibernate and did spend some time looking through it, but it is quite a bit of code to wade through but will continue to ramp up on it as I get time and have questions.