Description:
The value shown in MySQL status output for "Queries per second avg" is incorrect if it does not have 3 digits right of the decimal. This is regardless of how it is accessed; both "SHOW STATUS;" and `mysqladmin status` exhibit the behavior.
Because the floating point value is printed using integer division and modulo operations, it needs to be correctly zero padded. This happens regardless of what is left of the decimal point; however it skews this value a ton on something like a development server where 0.80 is a lot different than 0.080.
Seems to affect all versions my MySQL back to at least 5.0 if not way before. Bug 25615 is tangentially related.
How to repeat:
Start server, execute no queries for ~1 minute, run `mysqladmin status`. See the following:
$ mysqladmin status
Uptime: 50 Threads: 1 Questions: 3 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.60
And it should be:
$ mysqladmin status
Uptime: 50 Threads: 1 Questions: 3 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.060
Suggested fix:
diff -ur mysql-5.5.12-original/sql/sql_parse.cc mysql-5.5.12/sql/sql_parse.cc
--- mysql-5.5.12-original/sql/sql_parse.cc 2011-04-11 05:44:03.000000000 -0500
+++ mysql-5.5.12/sql/sql_parse.cc 2011-05-17 09:04:10.000000000 -0500
@@ -1308,7 +1308,7 @@
length= my_snprintf(buff, buff_len - 1,
"Uptime: %lu Threads: %d Questions: %lu "
"Slow queries: %lu Opens: %lu Flush tables: %lu "
- "Open tables: %u Queries per second avg: %u.%u",
+ "Open tables: %u Queries per second avg: %u.%03u",
uptime,
(int) thread_count, (ulong) thd->query_id,
current_global_status_var.long_query_count,