dotnet / dotnet/SqlClient

Consider not doing a roundtrip for BeginTransaction

Open
#1,554 19 comments 1 reaction 0 assignees View on GitHub
Performance :chart_with_upwards_trend:
Dominant language
C#
Stars
989
Forks
340
Avg merge
4d 18h
Merged PRs (30d)
69

Description

In Npgsql, calling DbConnection.BeginTransaction doesn't actually do anything - it simply sets an in-memory state flag. When a command is next actually executed on the connection, the begin transaction is prepended to it, so they are delivered as a single batch. This eliminates an additional roundtrip to the database, which can be quite significant. SqlClient could do the same.

Note that this may have visible side-effects, e.g. if BeginTransaction() can throw because of any sort of incorrect state (I'm not sure this can actually happen in SQL Server, but it does need to be taken into account). Even if that's the case, the elimination of a full roundtrip for the happy path would still likely justify this, IMHO.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.