koyr-exem opened a new issue, #908:
URL: https://github.com/apache/hugegraph-toolchain/issues/908

   ### Bug Type (问题类型)
   
   exception / error (异常报错)
   
   ### Before submit
   
   - [x] I had searched in the 
[issues](https://github.com/apache/hugegraph-toolchain/issues) and found no 
similar issues.
   
   ### Environment (环境信息)
   
   - Server Version: v1.7.0
   - Toolchain Version: v1.7.0 (hugegraph-loader; the same code is on current 
master)
   - Data Size: 1,000,000 vertices, 0 edges (PostgreSQL source table ~301 MB, 
reproduction case)
   - Source DB: PostgreSQL 16, JDBC driver postgresql-42.4.1 (bundled with the 
loader)
   
   
   ### Expected & Actual behavior (期望与实际表现)
   
   **Actual:** Loading a large PostgreSQL table through the JDBC input, the 
loader holds the **entire result set in heap** before producing the first batch 
and dies. `batch_size` has no effect on memory use; the required heap grows 
with the table size.
   
   ```java
   vertices/edges loaded this time : Terminating due to 
java.lang.OutOfMemoryError: Java heap space
   ```
   
   **Expected:** Rows are streamed in `batch_size` chunks, so memory does not 
depend on the table size.
   
   **Cause:** `JDBCFetcher.nextBatch()` (introduced in #683, replacing 
`RowFetcher`):
   
   ```java
   stmt = this.conn.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY);
   result = stmt.executeQuery(buildSql());     // "select * from <table>"
   result.setFetchSize(source.batchSize());    // set after the query has 
already run
   ```
   
   The PostgreSQL JDBC driver only fetches through a cursor when auto-commit is 
off **and** the fetch size is set on the statement **before** execution 
([pgjdbc 
docs](https://jdbc.postgresql.org/documentation/query/#getting-results-based-on-a-cursor)).
 Neither holds, so `executeQuery` reads every row into memory. MySQL 
Connector/J behaves the same by default.
   
   **Reproduce** (1,000,000-row table, ~301 MB, `batch_size: 500`):
   
   | Loader | Heap | Result |
   |---|---|---|
   | 1.7.0 | 256m | `OutOfMemoryError: Java heap space` |
   | 1.7.0 | 1g | OK (process peak ~910 MB) |
   | 1.7.0 + proposed fix | 256m | OK, 1,000,000 vertices inserted |
   
   **Proposed fix:** turn off auto-commit (if the driver supports it) and call 
`stmt.setFetchSize(batchSize)` before `executeQuery`. The fetcher is read-only, 
so nothing needs committing. I can open a PR.
   
   ### Vertex/Edge example (问题点 / 边数据举例)
   
   ```javascript
   -- Origin data (PostgreSQL 16)
   CREATE TABLE person AS
     SELECT g AS id, 'name_'||g AS name, repeat(md5(g::text), 8) AS payload
     FROM generate_series(1, 1000000) g;
   
   
   
   // struct.json
   
{"vertices":[{"label":"person","input":{"type":"jdbc","vendor":"postgresql","driver":"org.postgresql.Driver",
    
"url":"jdbc:postgresql://127.0.0.1:5432","database":"src","schema":"public","table":"person",
    "username":"postgres","password":"***","batch_size":500},
    "id":"id","field_mapping":{"name":"name"},"ignored":["payload"]}]}
   ```
   
   ### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
   
   ```javascript
   schema.propertyKey("name").asText().ifNotExist().create();
   
schema.vertexLabel("person").useCustomizeNumberId().properties("name").ifNotExist().create();
   ```


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to