Bug #106939 TRUNCATE performance_schema.accounts causes duplicated counts in global_status

Submitted: 7 Apr 2022 2:51 Modified: 13 May 2022 10:28
Reporter: yuxiang jiang (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Performance Schema Severity:S3 (Non-critical)
Version:5.7.18 OS:Any
Assigned to: Marc ALFF CPU Architecture:Any
Tags: Contribution, performance schema statistic

[7 Apr 2022 2:51] yuxiang jiang
Description:
Sometimes MySQL instance status infomation such as Slow_queries changed in a incredible way in short time. But we did not find any entries in slow log file.

How to repeat:
1,  turn on pfs
2,  set performance_schema_hosts_size=1 in configuration file
3, create user tu1@'%' identified by '123456';
4, connect root and tu1 with difference host to mysql
./bin/mysql -uroot -S mysql.sock
./bin/mysql -utu1 -p123456 --port=3307 --host=127.0.0.1
5, now mysql looks like this
==================================
mysql> select * from accounts;
+------+-----------+---------------------+-------------------+
| USER | HOST      | CURRENT_CONNECTIONS | TOTAL_CONNECTIONS |
+------+-----------+---------------------+-------------------+
| NULL | NULL      |                  87 |                90 |
| root | localhost |                   1 |                 1 |
| tu1  | localhost |                   1 |                 1 |
+------+-----------+---------------------+-------------------+
3 rows in set (0.00 sec)

mysql> select * from hosts;
+------+---------------------+-------------------+
| HOST | CURRENT_CONNECTIONS | TOTAL_CONNECTIONS |
+------+---------------------+-------------------+
| NULL |                  87 |                90 |
+------+---------------------+-------------------+
1 row in set (0.00 sec)

mysql> show global status like 'Performance_schema_hosts_lost';
+-------------------------------+-------+
| Variable_name                 | Value |
+-------------------------------+-------+
| Performance_schema_hosts_lost | 2     |
+-------------------------------+-------+
1 row in set (0.01 sec)
==================================
6, create some slow entry by tu1 connection
set long_query_time=0.1;
select sleep(1);select sleep(1);select sleep(1);
===========
now mysql looks like this
mysql> show global status like 'Slow_queries';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries  | 3     |
+---------------+-------+
1 row in set (0.02 sec)

===========
7, truncate accounts by root user
truncate table accounts;
===========
now mysqld looks like this
mysql> show global status like 'Slow_queries';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Slow_queries  | 6     |
+---------------+-------+
1 row in set (0.01 sec)

Suggested fix:
diff --git a/storage/perfschema/pfs_account.cc b/storage/perfschema/pfs_account.cc
index e8d36f8..f11bed8 100644
--- a/storage/perfschema/pfs_account.cc
+++ b/storage/perfschema/pfs_account.cc
@@ -541,7 +541,7 @@ void PFS_account::aggregate_status(PFS_user *safe_user, PFS_host *safe
       - GLOBAL_STATUS
     */
     safe_user->m_status_stats.aggregate(& m_status_stats);
-    m_status_stats.aggregate_to(& global_status_var);
+    //m_status_stats.aggregate_to(& global_status_var);
     m_status_stats.reset();
     return;
   }
@@ -561,7 +561,7 @@ void PFS_account::aggregate_status(PFS_user *safe_user, PFS_host *safe
     Aggregate STATUS_BY_ACCOUNT to:
     - GLOBAL_STATUS
   */
-  m_status_stats.aggregate_to(& global_status_var);
+  //m_status_stats.aggregate_to(& global_status_var);
   m_status_stats.reset();
   return;
 }
(
[11 Apr 2022 0:38] yuxiang jiang
rewrite title

contribution by Ten:Truncate pfs table accounts cause global status abnormal
[11 Apr 2022 0:38] yuxiang jiang
rewrite title

contribution by Ten:Truncate pfs table accounts cause global status abnormal
[11 Apr 2022 2:54] yuxiang jiang
rewrite title again
[11 Apr 2022 6:57] MySQL Verification Team
Hello yuxiang jiang,

Thank you for the report and contribution.
Please ensure to re-send the patch "Contribution" tab. Otherwise we would not be able to accept it.

regards,
Umesh
[11 Apr 2022 9:25] yuxiang jiang
patch for this defect

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: 0001-bugfix-issue-516-Truncate-pfs-table-accounts-will-ca.patch (application/octet-stream, text), 5.56 KiB.

[12 Apr 2022 14:40] Marc ALFF
Contribution by Tencent.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.