Skip to content
Discussion options

You must be logged in to vote

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:

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: EXPLAIN ANALYZE on Postgres gives you the planner/executor timing, and MySQL has profiling / the performance schema for it. sqlx…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pposca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants