P粉1868974652023-08-28 10:02:56
In JDBC, the setFetchSize(int)
method is very important for performance and memory management within the JVM because it controls the number of network calls from the JVM to the database and the corresponding amount of data. RAM used for result set processing.
Essentially, if setFetchSize(10) is called and the driver ignores it, there are only two possible options:
RESULT-SET is the number of rows marshalled on the database in response to the query. ROW-SET is a block of rows extracted from RESULT-SET on each call from JVM to DB. The number of these calls, and the RAM required for processing, depends on the fetch-size setting.
So if RESULT-SET has 100 rows and fetch-size is 10, At any given time, there are 10 network calls to retrieve all the data, using approximately 10*{row-content-size} RAM.
The default fetch-size is 10, which is quite small. In the case posted, the driver seems to be ignoring the fetch size setting, retrieving all data in one call (requires lots of RAM, optimally minimal network calls).
What happens under ResultSet.next()
is that it doesn't actually get one row at a time from the RESULT-SET. It gets that data from the (local) ROW-SET and gets the next ROW-SET (invisible) from the server when the data on the local client is exhausted.
All of this depends on the driver, as the setting is just a "hint", but in practice I have found that this is how many drivers and databases work (proven in many versions of Oracle, DB2 and MySQL). p>