sea-orm
sea-orm copied to clipboard
Postgres: SET TRANSACTION ISOLATION LEVEL & ACCESS MODE could be combined into a single statement
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