fix: GH-2407 Release JDBC statements as soon as their result is consumed - #2899
Open
Ilya Nemtsev (inemtsev) wants to merge 1 commit into
Open
Ilya Nemtsev (inemtsev) wants to merge 1 commit into
Ilya Nemtsev (inemtsev) wants to merge 1 commit into
Conversation
… is consumed Every executed statement was kept in the transaction's executedStatements list until the transaction ended, and a query's statement was only closed when its iterator reached the last row. A long-running transaction therefore accumulated one PreparedStatement per executed statement. Statements that do not hand out a result set (insert, update, delete, exec with a transform) are now closed right after the interceptors have run. Statements that do are registered with the transaction and released, and unregistered, as soon as their result is consumed by an iterator, count(), or empty(). A statement whose execution throws is closed as well, and the auxiliary statement used to read SQLite generated keys is closed together with its parent. Transaction-end cleanup, closeExecutedStatements(), and the eager cleanup for drivers without multiple result set support are unchanged.
Contributor
Author
|
I ran a few tests with a loop inside a transaction: Retention harness: one
environment: (PostgreSQL 18, JDK 21) |
Oleg Babichev (obabichevjb)
self-requested a review
August 27, 2026 13:07
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2407.
Problem
Every executed statement was kept in the transaction's executedStatements list until the transaction ended, and a query's statement was only closed when its iterator reached the last row. A long-running transaction therefore accumulated one PreparedStatement per executed statement. Causing the memory usage to grow considerably.
Description
Description Summary: executedStatements now holds only statements that still own an open result set.
Detailed description:
Type of Change
Please mark the relevant options with an "X":
Updates/remove existing public API methods:
Affected databases:
Checklist
Related Issues