Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres: SET TRANSACTION ISOLATION LEVEL & ACCESS MODE could be combined into a single statement #2287

Open
nickb937 opened this issue Jul 12, 2024 · 0 comments

Comments

@nickb937
Copy link
Contributor

Description

This may seem like a micro-optimisation, but establishing transactions with calls similar to this, causes two statements to be submitted to the DB where one would suffice:

        self.dbh
            .begin_with_config(Some(IsolationLevel::ReadCommitted), Some(AccessMode::ReadOnly))
            .await

And where the DB is remote, the time delay can be considerable - 27ms per statement due to the RTT:

{"timestamp":"2024-07-12T20:46:29.761474022+00:00","level":"INFO",
"fields":{"summary":"SET TRANSACTION ISOLATION LEVEL …","db.statement":"\n\nSET\n  TRANSACTION ISOLATION LEVEL READ COMMITTED\n",
"rows_affected":0,"rows_returned":0,
"elapsed":"27.372216ms"},
"target":"sqlx::query"}

{"timestamp":"2024-07-12T20:46:29.788290451+00:00","level":"INFO",
"fields":{"summary":"SET TRANSACTION READ ONLY","db.statement":"",
"rows_affected":0,"rows_returned":0,
"elapsed":"26.649573ms"},
"target":"sqlx::query"}

Solution would be to re-code this function to write the singular statement:

https://github.com/SeaQL/sea-orm/blob/master/src/driver/sqlx_postgres.rs#L267-L291

SET TRANSACTION ISOLATION_LEVEL REPEATABLE READ READ ONLY

Version:

SeaORM all versions

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

No branches or pull requests

1 participant