mysql duration and fetch time

MysqlMysql Workbench

Mysql Problem Overview


I am using MySQL workbench - What is the difference between duration and fetch times when a query is run?

Also is there a way I can enable the microsecond option in MySQL?

Mysql Solutions


Solution 1 - Mysql

Fetch time - measures how long transferring fetched results take, which has nothing to do with query execution. I would not consider it as sql query debugging/optimization option since fetch time depends on network connection, which itself does not have anything to do with query optimization. If fetch time is bottleneck then more likely there's some networking problem.

Note: fetch time may vary on each query execution.

Duration time - is the time that query needs to be executed. You should try to minimize it when optimizing performance of sql query.

Reference

Solution 2 - Mysql

Duration shows the time needed to execute the query and fetch is the time needed to read the result set (retrieve the data)

I am unsure about the microsecond option. If this is in regards to optimization, remember - "premature optimization is the root of all evil"

Solution 3 - Mysql

The answer of Leri is a good start but ignores the fact that MySQL can stream the data to client before having all the results of the query.

Below is an example with 2 queries with the same results. The first one use a group by, so MySQL have to calculate the full aggregate before sending all the data. The second one use a subquery so MySQL calculate row by row the results set and is able to send the first line of result to client immediately.

MySQL Workbench durations

As you can see, the fetch time of the second query is 5 time longer (for the same data), because MySQL Workbench show the time before the first received data as Duration and the time after as Fetch, but as streaming can be involved, it doesn't mean that fetch duration is network duration only.

During Fetch time, the database could still be calculating results. So, if you see a big fetch duration, you can actually do someting! It probably mean that you're MySQL database is streaming results rows one by one and struggling to calculate the full results set.

Solution 4 - Mysql

Execution time is time spent preparing the query and running the query AND The fetch time is time spent pulling-in the row results

Solution 5 - Mysql

About the microsecond, try to enable it in the Preferences menu, and I also got a question about the duration and fetch time before, now I seems get the answer that the duration is the execution time of the query, and the fetch is retrieve the result and send them to wherever you want. For example, I get a query which duration time is 0.078 but will take 60 secs to send the data back to my website.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1189851View Question on Stackoverflow
Solution 1 - MysqlLeriView Answer on Stackoverflow
Solution 2 - MysqlKurtView Answer on Stackoverflow
Solution 3 - MysqlPCOView Answer on Stackoverflow
Solution 4 - MysqlSatyamView Answer on Stackoverflow
Solution 5 - MysqlSpark8006View Answer on Stackoverflow