Bug #104240 Recheck documentation for Slow_queries
Submitted: 7 Jul 2021 18:11 Modified: 27 Aug 2021 5:40
Reporter: Oleksandr Kachan Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[7 Jul 2021 18:11] Oleksandr Kachan
Description:
There is the following description for Slow_queries status variable in docs
"The number of queries that have taken more than long_query_time seconds.
This counter increments regardless of whether the slow query log is enabled.".

As I can see from the code the only place where status_var.long_query_count is incremented is log_slow_do() function. In addition to this log_slow_do() gets invoked only in case slow query log is enabled (opt_slow_log is checked) and query passes checks in log_slow_applicable().

So is the "This counter increments regardless of whether the slow query log is enabled" part of Slow_queries description actually correct?

How to repeat:
Check documentation
[8 Jul 2021 6:05] MySQL Verification Team
Hello Oleksandr,

Thank you for the report.
Imho you are right, statement "This counter increments regardless of whether the slow query log is enabled. " sounds incorrect from below test results.

-- 8.0.25
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show global variables where variable_name in ('long_query_time','slow_query_log','log_slow_extra','log_slow_admin_statements');
+---------------------------+-----------+
| Variable_name             | Value     |
+---------------------------+-----------+
| log_slow_admin_statements | OFF       |
| log_slow_extra            | OFF       |
| long_query_time           | 10.000000 |
| slow_query_log            | OFF       |
+---------------------------+-----------+
4 rows in set (0.00 sec)

mysql> show variables where variable_name in ('long_query_time','slow_query_log','log_slow_extra','log_slow_admin_statements');
+---------------------------+-----------+
| Variable_name             | Value     |
+---------------------------+-----------+
| log_slow_admin_statements | OFF       |
| log_slow_extra            | OFF       |
| long_query_time           | 10.000000 |
| slow_query_log            | OFF       |
+---------------------------+-----------+
4 rows in set (0.01 sec)

mysql> show status like 'Slow_queries';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries  | 0     |
+---------------+-------+
1 row in set (0.00 sec)

mysql> select sleep(11), 'Hello Bug #104240' from dual;
+-----------+-------------------+
| sleep(11) | Hello Bug #104240 |
+-----------+-------------------+
|         0 | Hello Bug #104240 |
+-----------+-------------------+
1 row in set (11.01 sec)

mysql> show status like 'Slow_queries';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries  | 0     |
+---------------+-------+
1 row in set (0.00 sec)

mysql> set global slow_query_log=ON;
Query OK, 0 rows affected (0.07 sec)

mysql> show variables where variable_name in ('long_query_time','slow_query_log','log_slow_extra','log_slow_admin_statements');
+---------------------------+-----------+
| Variable_name             | Value     |
+---------------------------+-----------+
| log_slow_admin_statements | OFF       |
| log_slow_extra            | OFF       |
| long_query_time           | 10.000000 |
| slow_query_log            | ON        |
+---------------------------+-----------+
4 rows in set (0.00 sec)

mysql> show status like 'Slow_queries';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries  | 0     |
+---------------+-------+
1 row in set (0.00 sec)

mysql> select sleep(11), 'Hello Bug #104240' from dual;
+-----------+-------------------+
| sleep(11) | Hello Bug #104240 |
+-----------+-------------------+
|         0 | Hello Bug #104240 |
+-----------+-------------------+
1 row in set (11.01 sec)

mysql> show status like 'Slow_queries';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries  | 1     |
+---------------+-------+
1 row in set (0.00 sec)

regards,
Umesh
[8 Jul 2021 6:10] MySQL Verification Team
Related - Bug #91496
[27 Aug 2021 5:40] MySQL Verification Team
Marking this as duplicate of Bug #91496, once Bug #91496 is fixed then doc hanges will be updated accordingly.