SELECT `mt` . `THREAD_ID` AS `thread_id` , IF ( ( `t` . `NAME` = ? ) , `concat` ( `t` . `PROCESSLIST_USER` , ? , `t` . `PROCESSLIST_HOST` ) , REPLACE ( `t` . `NAME` , ?, ... ) ) AS `user` , SUM ( `mt` . `CURRENT_COUNT_USED` ) AS `current_count_used` , `sys` . `format_bytes` ( SUM ( `mt` . `CURRENT_NUMBER_OF_BYTES_USED` ) ) AS `current_allocated` , `sys` . `format_bytes` ( `ifnull` ( ( SUM ( `mt` . `CURRENT_NUMBER_OF_BYTES_USED` ) / `nullif` ( SUM ( `mt` . `CURRENT_COUNT_USED` ) , ? ) ) , ? ) ) AS `current_avg_alloc` , `sys` . `format_bytes` ( MAX ( `mt` . `CURRENT_NUMBER_OF_BYTES_USED` ) ) AS `current_max_alloc` , `sys` . `format_bytes` ( SUM ( `mt` . `SUM_NUMBER_OF_BYTES_ALLOC` ) ) AS `total_allocated` FROM ( `performance_schema` . `memory_summary_by_thread_by_event_name` `mt` JOIN `performance_schema` . `threads` `t` ON ( ( `mt` . `THREAD_ID` = `t` . `THREAD_ID` ) ) ) GROUP BY `mt` . `THREAD_ID` , IF ( ( `t` . `NAME` = ? ) , `concat` ( `t` . `PROCESSLIST_USER` , ? , `t` . `PROCESSLIST_HOST` ) , REPLACE 