Bug #61205 "Queries per second avg" value in status output is incorrect
Submitted: 17 May 2011 16:32 Modified: 22 Jul 2011 18:15
Reporter: Dan McGee Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Performance Schema Severity:S3 (Non-critical)
Version:5.5.12 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, mysqladmin, qps, STATUS
Triage: Needs Triage: D3 (Medium)

[17 May 2011 16:32] Dan McGee
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,
[17 May 2011 17:12] Valeriy Kravchuk
Thank you for the bug report and patch contributed. Verified with current mysql-5.1 and mysql-5.5 on Mac OS X.
[22 Jul 2011 18:15] Paul Dubois
Noted in 5.5.15, 5.6.3 changelogs.

The fractional part of the "Queries per second" value in MySQL status
output could be displayed incorrectly.