Skip to content

Conversation

@olavloite
Copy link
Collaborator

Adds a BeginTransactionOption configuration field that can be used to determine how the database/sql driver should begin transactions. The default is to inline the BeginTransaction option with the first SQL statement of the transaction. This reduces the number of round-trips needed per transaction by one for most transaction shapes.

Adds a BeginTransactionOption configuration field that can be used to
determine how the database/sql driver should begin transactions. The
default is to inline the BeginTransaction option with the first SQL
statement of the transaction. This reduces the number of round-trips
needed per transaction by one for most transaction shapes.
@olavloite olavloite requested a review from a team as a code owner July 1, 2025 17:08
@olavloite olavloite requested a review from rahul2393 July 1, 2025 18:18
@olavloite olavloite merged commit 3d26ee4 into inline-begin-tx Jul 1, 2025
14 checks passed
@olavloite olavloite deleted the begin-tx-option branch July 1, 2025 19:24
olavloite added a commit that referenced this pull request Jul 2, 2025
* perf: inline BeginTransaction with first statement

Inline the BeginTransaction option with the first statement in the transaction,
instead of executing a separate BeginTransaction RPC. This reduces the number
of round-trips to Spanner by one for all transactions that have at least one
SQL statement.

Using line-begin improves performance for most transaction shapes, as it requires
one less round-trip to Spanner. Some transaction shapes do not benefit from this.
These are:
1. Transactions that only write mutations still need an explicit BeginTransaction
   RPC to be executed, as mutations are included in the Commit RPC. The Commit
   RPC can also start a transaction, but such transactions are not guaranteed to
   be applied only once to Spanner.
2. Transactions that execute multiple parallel queries at the start of the
   transaction can see higher end-to-end execution times, as only one query
   can include the BeginTransaction option. All other queries must wait for
   the first query to return at least one result, which also includes the
   transaction identifier, before they can proceed.

The default for the database/sql driver is to use inline-begin.
A follow-up pull request will add an option to the driver to set a different
default for a connection.

* feat: add BeginTransactionOption (#467)

Adds a BeginTransactionOption configuration field that can be used to
determine how the database/sql driver should begin transactions. The
default is to inline the BeginTransaction option with the first SQL
statement of the transaction. This reduces the number of round-trips
needed per transaction by one for most transaction shapes.
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.

3 participants