MySQL now reports 3 decimal places for milliseconds
Motivation
At Readyset, we frequently analyze query latency to fine-tune performance. Our built-in metrics provide end-to-end timing breakdowns, helping us measure everything from query parsing to execution (whether it’s a cache hit or miss).
We often deal with extremely fast queries — some completing in as little as 5 microseconds (μs) at p50 and 12.5μs at p99. However, when using the standard mysql client, we noticed an issue:
Queries that take less than a second are reported with only two decimal places. For example:
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,00 sec)
At first glance, it looks like the query took exactly 0 milliseconds, but that’s misleading. The actual execution time could be anywhere between 0.000 and 0.009 seconds — a missing level of precision that makes it difficult to measure sub-millisecond latencies.
For instance, if a query took 5μs, that means we could theoretically execute it 1,800 times in just 9ms, but the current reporting doesn’t reflect that level of accuracy.
Fixing the Issue & Community Engagement
To address this, I initially patched my local MySQL client to display three decimal places. Before submitting my fix, I researched existing bug reports and found that Daniel had submitted a patch a few years ago (Bug #84007). His patch had received review comments but wasn’t fully merged.
Rather than starting from scratch, I decided to build on Daniel’s work and address the review feedback. I submitted a GitHub PR, which was later converted into an official MySQL bug (Bug #117270). This time, it was accepted and will be included in MySQL 9.3.
With this fix, MySQL now properly reports milliseconds with three decimal places:
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,002 sec)
Previously, this query would have shown 0.00 sec, omitting the fact that it actually took 2ms to complete (which, in this case, was likely due to Docker network overhead).
This was a fun community contribution, and I’m excited to see it land in MySQL 9.3! 🎉