Repository navigation
Get the query execution duration #4325
|
Hello, Is there a way of getting the query execution time as a value? I mean, not as a log, but as a value you can store in a variable. I've been trying SeaORM, which uses sqlx under the hood, and there wasn't any way of doing it, more than showing sqlx logs. Thanks! |
Replies: 1 comment
|
There's no sqlx API that hands you the execution time as a value, the timings you see are only emitted through its let start = std::time::Instant::now();
let rows = sqlx::query("...").fetch_all(&pool).await?;
let elapsed = start.elapsed();Just keep in mind that's wall-clock for the whole round trip, so it includes pool checkout, network and decoding, not only what the server spent. If you specifically want the database-side execution time you have to ask the DB itself: |
There's no sqlx API that hands you the execution time as a value, the timings you see are only emitted through its
tracing/log instrumentation. So the simplest thing is to measure it yourself around the call:Just keep in mind that's wall-clock for the whole round trip, so it includes pool checkout, network and decoding, not only what the server spent. If you specifically want the database-side execution time you have to ask the DB itself:
EXPLAIN ANALYZEon Postgres gives you the planner/executor timing, and MySQL has profiling / the performance schema for it. sqlx…