Commit 66d5e47
committed
Start transaction before prepare call (1.4)
This is a backport of the PR #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.1 parent ea919f8 commit 66d5e47
1 file changed
+9
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
| |||
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| |||
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
183 | | - | |
| 184 | + | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
| |||
657 | 658 | | |
658 | 659 | | |
659 | 660 | | |
660 | | - | |
| 661 | + | |
661 | 662 | | |
662 | 663 | | |
663 | 664 | | |
| |||
690 | 691 | | |
691 | 692 | | |
692 | 693 | | |
693 | | - | |
| 694 | + | |
694 | 695 | | |
695 | 696 | | |
696 | 697 | | |
| |||
0 commit comments