8000 Send single payload in BeginTransactionAsync · Issue #1286 · mysql-net/MySqlConnector · GitHub
[go: up one dir, main page]

Skip to content
Send single payload in BeginTransactionAsync #1286
Closed
@DomoYao

Description

@DomoYao

Discussion summary: Revert change in #774 and use Pipelining = false for databases that don't support a single payload. This will reduce the round-trips from 2 to 1 when starting a transaction.


private async ValueTask<MySqlTransaction> **BeginTransactionAsync**(IsolationLevel isolationLevel, bool? isReadOnly, IOBehavior ioBehavior, CancellationToken cancellationToken)
	{
		using (var cmd = new MySqlCommand($"set session transaction isolation level {isolationLevelValue};", this) { NoActivity = true })
		{
			await cmd.ExecuteNonQueryAsync(ioBehavior, cancellationToken).ConfigureAwait(false);

			var consistentSnapshotText = isolationLevel == IsolationLevel.Snapshot ? " with consistent snapshot" : "";
			var readOnlyText = isReadOnly switch
			{
				true => " read only",
				false => " read write",
				null => "",
			};
			var separatorText = (consistentSnapshotText.Length == 0 || readOnlyText.Length == 0) ? "" : ",";
			cmd.CommandText = $"start transaction{consistentSnapshotText}{separatorText}{readOnlyText};";
			await cmd.ExecuteNonQueryAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
		}

		var transaction = new MySqlTransaction(this, isolationLevel);
		CurrentTransaction = transaction;
		return transaction;
	}

Can't the default level of the database be used?
This class seems to be one more database operation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0