Skip to content

feat!(c/driver/postgresql): defer transaction start - #4424

Merged
lidavidm merged 5 commits into
apache:mainfrom
lidavidm:gh-4321
Jun 23, 2026
Merged

feat!(c/driver/postgresql): defer transaction start#4424
lidavidm merged 5 commits into
apache:mainfrom
lidavidm:gh-4321

Conversation

@lidavidm

@lidavidm lidavidm commented Jun 22, 2026

Copy link
Copy Markdown
Member
  • Use ROLLBACK and not ROLLBACK AND CHAIN, which unexpectedly preserves transaction properties
  • Lazily start transactions instead of eagerly
    • For pooled connections, this is better behavior
    • We do make slightly more server round-trips

Closes #4321.

Assisted-by: GPT-5.5 codex@openai.com

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the PostgreSQL C driver’s transaction behavior to avoid implicitly chaining transactions on COMMIT/ROLLBACK and to start transactions lazily (on first use) when autocommit is disabled—improving behavior with pooled connections.

Changes:

  • Switch COMMIT; BEGIN TRANSACTIONCOMMIT and ROLLBACK AND CHAINROLLBACK.
  • Add PostgresConnection::EnsureTransaction() and invoke it before statement execution and selected metadata calls when autocommit is disabled.
  • Update/add Python and C++ tests to reflect “idle after commit/rollback” and to validate non-chaining rollback behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/adbc_driver_postgresql/tests/test_dbapi.py Updates txn-status expectations; adds a cross-connection transaction behavior test.
c/driver/postgresql/statement.cc Ensures a transaction exists before executing queries/ingest when autocommit is disabled.
c/driver/postgresql/postgresql_test.cc Adjusts txn-status assertions; adds tests for non-chaining rollback and lazy txn start in GetObjects.
c/driver/postgresql/connection.h Exposes EnsureTransaction() to PostgresStatement via friendship.
c/driver/postgresql/connection.cc Implements lazy transaction start; changes COMMIT/ROLLBACK semantics; updates autocommit toggle behavior and adds EnsureTransaction calls in metadata paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread c/driver/postgresql/connection.cc
Comment thread python/adbc_driver_postgresql/tests/test_dbapi.py
@lidavidm
lidavidm requested review from amoeba and zeroshade June 22, 2026 07:24
@lidavidm
lidavidm marked this pull request as ready for review June 22, 2026 07:24
Comment thread c/driver/postgresql/connection.cc
@lidavidm
lidavidm merged commit 87989bf into apache:main Jun 23, 2026
87 of 89 checks passed
@lidavidm
lidavidm deleted the gh-4321 branch June 23, 2026 23:52
@lidavidm lidavidm added this to the ADBC Libraries 24 milestone Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[postgresql] option to use ROLLBACK instead of ROLLBACK AND CHAIN

3 participants