Rich Mugge
06/17/2026, 3:09 PMuseCursorFetch for batched reads with a cursor?Rocky
06/17/2026, 3:09 PMuseCursorFetch property for server-side cursors. While StarRocks is compatible with the MySQL wire protocol, it does not implement the server-side cursor mechanism that useCursorFetch=true relies on in the MySQL JDBC driver.
If you attempt to use useCursorFetch=true, the client may fall back to default behavior (fetching the entire result set into memory) or fail to achieve the intended batching behavior.
Recommended Alternatives
To handle large result sets without causing OutOfMemoryError (OOM) on your client, you should use one of the following methods:
1. JDBC Streaming Mode (Standard MySQL JDBC)
The most common way to "stream" data from StarRocks using a MySQL-compatible driver is to set the fetch size to Integer.MIN_VALUE. This tells the driver to read results row-by-row from the network stream rather than buffering the whole set.
java
// Must use TYPE_FORWARD_ONLY and CONCUR_READ_ONLY
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
// This is the magic value for MySQL JDBC streaming
stmt.setFetchSize(Integer.MIN_VALUE);
ResultSet rs = stmt.executeQuery("SELECT * FROM large_table");
while (rs.next()) {
// Process rows one by one
}
2. Arrow Flight SQL (High Performance)
For versions 3.5.1 and later, StarRocks supports the Arrow Flight SQL protocol. This is significantly faster than standard JDBC for large reads because it uses a fully columnar data transfer pipeline (zero-copy).
* Driver: Use the jdbc:arrow-flight-sql driver.
* Benefits: It eliminates the row-column conversion overhead and is designed for high-throughput batch reads.
3. StarRocks Connector/J
If you are using the native StarRocks JDBC Driver (starrocks-connector-j), it is designed to work efficiently with the StarRocks backend. For very large datasets, it is still recommended to use the Arrow Flight SQL integration mentioned above for the best performance.
Summary
* `useCursorFetch`: Not supported (no server-side cursors).
* Batch Reads: Use setFetchSize(Integer.MIN_VALUE) for row-by-row streaming.
* Best Practice: Use Arrow Flight SQL for massive data exports or large-scale data unloading/reading.
References
• unloading/arrow_flight.md
• unloading/Spark_connector.md
• faq/Sql_faq.md
• sql-reference/sql-statements/table_bucket_part_index/SELECT.md