Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using findIterate with MySQL streams the entire result set at once #56

Closed
Ronnie76er opened this issue Nov 4, 2013 · 7 comments
Closed
Labels

Comments

@Ronnie76er
Copy link

Using findIterate streams the entire result set. If it's particularly large, this could cause a Java OutOfMemoryError when calling findIterate.

According to the MySQL JDBC documentation, it seems like the statement needs to be constructed like this for streaming to work correctly:

stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
              java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);

MySQL JDBC doc: http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-implementation-notes.html
Google Group Topic: https://groups.google.com/forum/#!topic/ebean/PaMDPEetbJI

@rbygrave
Copy link
Member

rbygrave commented Nov 7, 2013

I have pushed up a fix. On the DatabasePlatform there is a forwardOnlyHintOnFindIterate. This is set to true on the MySqlPlatform. For creating PreparedStatements for findIterate() and findVisit() this databasePlatform hint is checked and if set creates the statement with the appropriate hints.

So out of the box this fix is specific to MySql and findIterate() or findVisit().

If you can pull/build and confirm this fixes your specific case that would be great.

@Ronnie76er
Copy link
Author

Thanks, I'll give it a shot this week and let you know how it goes.

@Ronnie76er
Copy link
Author

Sorry for the delay. This seems to be working well now.

I tested this in my play application, first without it there, and then with it there. Without it, the memory after using findIterate, but before iterating through the values, had sharply risen.

Updating to use 3.2.5, the memory didn't start going down until after iterating through the list provided by findIterate.

@rbygrave
Copy link
Member

Right so I'll close this issue as fixed then.

@rbygrave rbygrave added this to the 3.2.6 milestone Apr 2, 2014
@Ronnie76er
Copy link
Author

I apologize, but I think it may still be gathering the entire resultset in memory. Using a debugger on the code, it seems that the fetchSize is getting set to 0, instead of Integer.MIN_VALUE. I think the fetchSize getting set is important to indicate to the driver that the results should be streamed.

@rbygrave
Copy link
Member

Yes, I have reproduced this and it is not fixed without

pstmt.setFetchSize(Integer.MIN_VALUE);

@rbygrave rbygrave reopened this May 15, 2014
rbygrave added a commit that referenced this issue May 15, 2014
@rbygrave
Copy link
Member

Fixed in 4.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants