Bug #80523 current_memory in sys.session can go negative!
Submitted: 26 Feb 2016 9:23 Modified: 26 Feb 2016 10:50
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Performance Schema Severity:S3 (Non-critical)
Version:8.0.0, 8.0.11 OS:Microsoft Windows
Assigned to: Marc Alff CPU Architecture:Any

[26 Feb 2016 9:23] Shane Bester
Description:
Seen today on 5.8

mysql> select * from sys.session where current_memory < 1\G
*************************** 1. row ***************************
                thd_id: 30
               conn_id: 6
                  user: NULL
                    db: test
               command: Query
                 state: starting
                  time: 0
     current_statement: commit
     statement_latency: 292.68 ms
              progress: NULL
          lock_latency: 0 ps
         rows_examined: 0
             rows_sent: 0
         rows_affected: 0
            tmp_tables: 0
       tmp_disk_tables: 0
             full_scan: NO
        last_statement: NULL
last_statement_latency: NULL
        current_memory: -17544668 bytes <----------
             last_wait: NULL
     last_wait_latency: NULL
                source: NULL
           trx_latency: NULL
             trx_state: NULL
        trx_autocommit: NULL
                   pid: 5688
          program_name: NULL
1 row in set (0.11 sec)

How to repeat:
no exact testcase yet.
[26 Feb 2016 10:50] Shane Bester
found the culprit in my tests.
-------------------------------
With memory instrumentation enabled....

mysql> select * from sys.session where current_memory\G
*************************** 1. row ***************************
                thd_id: 28
               conn_id: 4
                  user: NULL
                    db: test
               command: Query
                 state: Sending data
                  time: 0
     current_statement: select * from sys.session where current_memory
     statement_latency: 2.19 ms
              progress: NULL
          lock_latency: 1.50 ms
         rows_examined: 0
             rows_sent: 0
         rows_affected: 0
            tmp_tables: 4
       tmp_disk_tables: 1
             full_scan: YES
        last_statement: NULL
last_statement_latency: NULL
        current_memory: 3.02 MiB
             last_wait: NULL
     last_wait_latency: NULL
                source: NULL
           trx_latency: NULL
             trx_state: NULL
        trx_autocommit: NULL
                   pid: 9640
          program_name: mysql
1 row in set (0.06 sec)

mysql> set global key_buffer_size = 1024 * 64;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from sys.session where current_memory\G
*************************** 1. row ***************************
                thd_id: 28
               conn_id: 4
                  user: NULL
                    db: test
               command: Query
                 state: Sending data
                  time: 0
     current_statement: select * from sys.session where current_memory
     statement_latency: 2.14 ms
              progress: NULL
          lock_latency: 1.50 ms
         rows_examined: 0
             rows_sent: 0
         rows_affected: 0
            tmp_tables: 4
       tmp_disk_tables: 1
             full_scan: YES
        last_statement: NULL
last_statement_latency: NULL
        current_memory: -5161446 bytes
             last_wait: NULL
     last_wait_latency: NULL
                source: NULL
           trx_latency: NULL
             trx_state: NULL
        trx_autocommit: NULL
                   pid: 9640
          program_name: mysql
1 row in set (0.06 sec)
[4 Mar 2016 8:42] Shane Bester
complete outputs

Attachment: bug80523_output.txt (text/plain), 1.25 MiB.

[18 Jun 2016 21:36] Omer Barnir
Posted by developer:
 
Reported version value updated to reflect release name change from 5.8 to 8.0
[25 Jun 2018 5:01] Umesh Shastry
Bug #91396 marked as duplicate of this one.
Also, updating the recent version reported "8.0.11".
[29 Jun 2018 14:19] Peter Zaitsev
I also would update it does not seems to be OS specific
I observed it on Linux