Bug #107741 Event_Scheduler memory leak in MySQL 8 version
Submitted: 4 Jul 2022 7:40 Modified: 6 Jul 2022 9:01
Reporter: Jialin Li Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S5 (Performance)
Version:8.0.25, 8.0.29 OS:Linux
Assigned to: CPU Architecture:Any

[4 Jul 2022 7:40] Jialin Li
Description:
mysql> select * from memory_by_thread_by_current_bytes limit 5;

+-----------+--------------------------+--------------------+-------------------+-------------------+-------------------+-----------------+
| thread_id | user                     | current_count_used | current_allocated | current_avg_alloc | current_max_alloc | total_allocated |
+-----------+--------------------------+--------------------+-------------------+-------------------+-------------------+-----------------+
|    819688 | sql/event_scheduler      |          467670009 | 23.28 GiB         |   53 bytes        | 10.44 GiB         | 1.02 TiB        |
|        45 | innodb/clone_gtid_thread |              83231 | 1.33 GiB          | 16.73 KiB         | 1.30 GiB          | 289.69 GiB      |
|        36 | innodb/dict_stats_thread |             119139 | 39.99 MiB         |  351 bytes        | 39.99 MiB         | 265.32 GiB      |
|  65324832 | root@localhost           |                 99 | 1.10 MiB          | 11.40 KiB         | 862.33 KiB        | 15.79 MiB       |
|         1 | sql/main                 |               9994 | 1.03 MiB          |  107 bytes        | 312.08 KiB        | 22.41 GiB       |
+-----------+--------------------------+--------------------+-------------------+-------------------+-------------------+-----------------+
5 rows in set (0.12 sec)

How to repeat:
create database if not exists meta;
use meta;
create table my_heartbeat (
  id int unsigned not null primary key,
  master_ts varchar(26) NOT NULL,
  update_by varchar(128) default NULL
);

create or replace view my_heartbeat_status_v as
  select
    master_ts,
    now(6) as time_now,
    unix_timestamp(now(6)) - unix_timestamp(master_ts) as slave_lag_seconds,
    update_by
  from my_heartbeat
;

insert into my_heartbeat (id, master_ts, update_by) values (1, NOW(6), 'init') on duplicate key update master_ts=NOW(6), update_by=VALUES(update_by);

#8.0
create event if not exists
  update_heartbeat_event
  on schedule every 1 second starts current_timestamp
  on completion preserve
  enable
  do  
    insert into my_heartbeat (id, master_ts, update_by) values (1, NOW(6), 'event_scheduler') as hb on duplicate key update master_ts=NOW(6), update_by=hb.update_by;

Suggested fix:
prevent memory leak
[6 Jul 2022 9:01] MySQL Verification Team
Hello Jialin Li,

Thank you for the report and feedback.

regards,
Umesh