nacz0 commented on issue #26661:
URL: https://github.com/apache/beam/issues/26661#issuecomment-7309696517

   This OOM comes from MySQL Connector/J, not Beam's query: by default the 
driver ignores positive fetch sizes and buffers the entire result set inside 
`executeQuery()` (`NativeProtocol.readAllResults` in the stack trace above), 
even with JdbcIO's default `fetchSize` of 50,000.
   
   Reproduced with Connector/J 8.0.22 on 400k × ~1 KB rows (~381 MB, 256 MB 
heap, `JdbcIO.ReadFn` statement settings):
   
   | Fetch size | Connection properties | Result |
   |---|---|---|
   | `50,000` (default) | `socketTimeout=60000` | `SQLException: Java heap 
space` |
   | `Integer.MIN_VALUE` | `socketTimeout=60000` | 400k rows, peak heap 152 MB, 
4.2 s |
   | `50,000` | `useCursorFetch=true;socketTimeout=60000` | 400k rows, peak 
heap 165 MB, 5.7 s |
   
   Workarounds:
   - **Java (`read` / `readRows` / `readAll`):** 
`.withFetchSize(Integer.MIN_VALUE)` streams rows one by one (since 2.43.0 / 
#23441).
   - **Any SDK (Python/Go/YAML):** set `useCursorFetch=true` in the JDBC URL 
(or `connection_properties`) to fetch in batches via server-side cursors. Note 
that this switches Connector/J to the binary protocol (affecting `FLOAT` 
rendering), so enabling it automatically isn't safe.
   
   I plan to open a PR to close the remaining gaps 
(`JdbcReadSchemaTransformProvider` dropping `Integer.MIN_VALUE`, 
`ReadFromMySqlSchemaTransformProvider` ignoring `useCursorFetch=true` in 
`connection_properties`, and `readWithPartitions().withFetchSize()` rejecting 
`Integer.MIN_VALUE`) and document this behavior across Java, YAML/Managed, and 
Python.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to