This is an automated email from the ASF dual-hosted git repository. ntimofeev pushed a commit to branch STABLE-4.1 in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 0808b2eb0762b67250b1ea4757d76f7c1e044e51 Author: Nikita Timofeev <stari...@gmail.com> AuthorDate: Wed Jul 22 12:36:01 2020 +0300 A note on MySQL JDBC driver and iterated queries --- .../src/docs/asciidoc/_cayenne-guide/part2/tuning.adoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/tuning.adoc b/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/tuning.adoc index 4b6da82..b8f24bd 100644 --- a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/tuning.adoc +++ b/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/tuning.adoc @@ -234,6 +234,23 @@ try(ResultBatchIterator<Artist> it = ObjectSelect.query(Artist.class).batchItera } ---- +===== MySQL JDBC driver and iterated queries + +The MySQL JDBC driver is known to pull the entire ResultSet into memory. +In order to get the driver to stream the results, append the JDBC parameter +`useCursorFetch=true` to the JDBC URL. + +A fetch size must also be set when doing the query using +`ObjectSelect.statementFetchSize(..)`, for example: +[source, java] +---- +ObjectSelect.query(queryClass) + .statementFetchSize(50000) + .iterate(objectContext, cayenneObject -> ... +---- +Adjust the value of the fetch size to fit requirements. A larger value is more +performant, but consumes more memory as well. + ==== Paginated Queries Enabling query pagination allows to load very large result sets in a Java app with very little memory overhead