Start transaction before prepare call (1.4)#468
Merged
staticlibs merged 1 commit intoduckdb:v1.4-andiumfrom Nov 28, 2025
Merged
Start transaction before prepare call (1.4)#468staticlibs merged 1 commit intoduckdb:v1.4-andiumfrom
staticlibs merged 1 commit intoduckdb:v1.4-andiumfrom
Conversation
This is a backport of the PR duckdb#467 to `v1.4-andium` stable branch. Previously, when auto-commit if off, the implicit transaction was started automatically when `PreparedStatement#execute(void)` is called. This was found to cause the problems with `Statement#executeQuery(String)`, that calls `prepare(String)` and `execute()` internally. As transaction was starting only after `prepare` call - the `prepare` itself was running with effective auto-commit mode (in a separate implicit transaction). It is harmless in most cases, but was found to break transaction-wide caching in `duckdb-iceberg`. The problem was only happening when the `execute(String)` is running outside of active transaction, for example as a first call in freshly opened connection. Still this was causing non-negligible overhead. This change makes the implicit transaction to be started before `prepare` call, so the same transaction is active during `execute` call. There are no changes in logic when auto-commit is on (default per JDBC spec), so the Iceberg caching is still broken in this mode. This is intended to be fixed in future, for now to have effective caching with `duckdb-iceberg` it is necessary to disable auto-commit, it can be done by one of the following methods: In connection config: ```java Properties config = new Properties(); config.put(DuckDBDriver.JDBC_AUTO_COMMIT, false); Connection conn = DriverManager.getConnection(url, config); ``` In connection URL: ```java Connection conn = DriverManager.getConnection("jdbc:duckdb:path/to/my.db;jdbc_auto_commit=false;"); ``` On a connection manually: ```java conn.setAutoCommit(false); ``` Testing: there are no easily observable effects from this change, the transactional logic is covered by existing tests, Iceberg caching is tested manually.
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.
This is a backport of the PR #467 to
v1.4-andiumstable branch.Previously, when auto-commit if off, the implicit transaction was started automatically when
PreparedStatement#execute(void)is called. This was found to cause the problems withStatement#executeQuery(String), that callsprepare(String)andexecute()internally. As transaction was starting only afterpreparecall - theprepareitself was running with effective auto-commit mode (in a separate implicit transaction). It is harmless in most cases, but was found to break transaction-wide caching induckdb-iceberg.The problem was only happening when the
execute(String)is running outside of active transaction, for example as a first call in freshly opened connection. Still this was causing non-negligible overhead.This change makes the implicit transaction to be started before
preparecall, so the same transaction is active duringexecutecall.There are no changes in logic when auto-commit is on (default per JDBC spec), so the Iceberg caching is still broken in this mode. This is intended to be fixed in future, for now to have effective caching with
duckdb-icebergit is necessary to disable auto-commit, it can be done by one of the following methods:In connection config:
In connection URL:
On a connection manually:
Testing: there are no easily observable effects from this change, the transactional logic is covered by existing tests, Iceberg caching is tested manually.