Description:
The HIGH_NUMBER_OF_BYTES_USED column in performance_schema.memory_summary_global_by_event_name does not appear to be correct. For example, this is the output from two identical queries fairly close together in time (in the same session):
```
mysql> SELECT * FROM performance_schema.memory_summary_global_by_event_name where HIGH_NUMBER_OF_BYTES_USED > 1000000000 and EVENT_NAME like '%openssl%';
+--------------------------------------+-------------+------------+---------------------------+--------------------------+----------------+--------------------+-----------------+--------------------------+------------------------------+---------------------------+
| EVENT_NAME | COUNT_ALLOC | COUNT_FREE | SUM_NUMBER_OF_BYTES_ALLOC | SUM_NUMBER_OF_BYTES_FREE | LOW_COUNT_USED | CURRENT_COUNT_USED | HIGH_COUNT_USED | LOW_NUMBER_OF_BYTES_USED | CURRENT_NUMBER_OF_BYTES_USED | HIGH_NUMBER_OF_BYTES_USED |
+--------------------------------------+-------------+------------+---------------------------+--------------------------+----------------+--------------------+-----------------+--------------------------+------------------------------+---------------------------+
| memory/mysqld_openssl/openssl_malloc | 435092455 | 435069816 | 46684243417 | 46665167493 | 0 | 22639 | 3466074 | 0 | 19075924 | 4088561393 |
+--------------------------------------+-------------+------------+---------------------------+--------------------------+----------------+--------------------+-----------------+--------------------------+------------------------------+---------------------------+
1 row in set (0.06 sec)
mysql> SELECT * FROM performance_schema.memory_summary_global_by_event_name where HIGH_NUMBER_OF_BYTES_USED > 1000000000 and EVENT_NAME like '%openssl%';
+--------------------------------------+-------------+------------+---------------------------+--------------------------+----------------+--------------------+-----------------+--------------------------+------------------------------+---------------------------+
| EVENT_NAME | COUNT_ALLOC | COUNT_FREE | SUM_NUMBER_OF_BYTES_ALLOC | SUM_NUMBER_OF_BYTES_FREE | LOW_COUNT_USED | CURRENT_COUNT_USED | HIGH_COUNT_USED | LOW_NUMBER_OF_BYTES_USED | CURRENT_NUMBER_OF_BYTES_USED | HIGH_NUMBER_OF_BYTES_USED |
+--------------------------------------+-------------+------------+---------------------------+--------------------------+----------------+--------------------+-----------------+--------------------------+------------------------------+---------------------------+
| memory/mysqld_openssl/openssl_malloc | 435148837 | 435125910 | 46690592744 | 46671143556 | 0 | 22927 | 3466780 | 0 | 19449188 | 4089464053 |
+--------------------------------------+-------------+------------+---------------------------+--------------------------+----------------+--------------------+-----------------+--------------------------+------------------------------+---------------------------+
1 row in set (0.05 sec)
```
The second query shows that the HIGH_NUMBER_OF_BYTES_USED has increased since the first query. This implies that the memory for this event increased from 19075924 (the original USED) to 4089464053 (the new HIGH) and then back down to 19449188 (the new USED).
This implies that, at least, 4089464053 - 19075924 (= 4,070,388,129) bytes must have been allocated in this interval (assuming no frees until the new HIGH was reached).
However, the number of bytes allocated during this period is exactly (new SUM_ALLOC - old SUM_ALLOC) 46690592744 - 46684243417 (= 6,349,327)
Thus, since ~6MB is much less than ~4TB, I conclude that at least one of the numbers is incorrect. I suspect that the incorrect number is the HIGH_NUMBER_OF_BYTES_USED
This is making it difficult to debug an out-of-memory problem...
How to repeat:
Run the following SQL on a database. If the result shows nothing, then runs some workload against the database, and then `drop table t2` and recreate it and then run the final query. Any output from the final query demonstrates the problem.
create temporary table t1 select * FROM performance_schema.memory_summary_global_by_event_name;
show status like 'foo';
show full processlist;
select sleep(10);
select * from t1;
create temporary table t2 select * FROM performance_schema.memory_summary_global_by_event_name;
select t1.EVENT_NAME, t2.HIGH_NUMBER_OF_BYTES_USED - t1.CURRENT_NUMBER_OF_BYTES_USED as RequiredAlloc, t2.SUM_NUMBER_OF_BYTES_ALLOC - t1.SUM_NUMBER_OF_BYTES_ALLOC as ActualAlloc from t1 join t2 on t1.EVENT_NAME = t2.EVENT_NAME and t1.HIGH_NUMBER_OF_BYTES_USED <> t2.HIGH_NUMBER_OF_BYTES_USED where t2.HIGH_NUMBER_OF_BYTES_USED - t1.CURRENT_NUMBER_OF_BYTES_USED > t2.SUM_NUMBER_OF_BYTES_ALLOC - t1.SUM_NUMBER_OF_BYTES_ALLOC;
Sample output in my case:
+--------------------------------------+---------------+-------------+
| EVENT_NAME | RequiredAlloc | ActualAlloc |
+--------------------------------------+---------------+-------------+
| memory/sql/MPVIO_EXT::auth_info | 40104 | 41 |
| memory/mysqld_openssl/openssl_malloc | 14270061 | 53024 |
| memory/temptable/physical_ram | 3145824 | 1048608 |
+--------------------------------------+---------------+-------------+
3 rows in set (0.03 sec)