Profiling memory usage in MySQL
Apr 11, 2024Ben Dicken

Summary
This post introduces and details methods for profiling memory usage in MySQL queries. It explains how to use `performance_schema.setup_instruments` and `performance_schema.memory_summary_by_thread_by_event_name` to monitor memory consumption at a thread level. The post provides SQL queries for sampling memory usage and presents Python scripts for collecting and visualizing this data over time, including a version with Matplotlib for live plotting. It highlights specific memory categories like `memory/sql/Filesort_buffer::sort_keys` and discusses the trade-offs and limitations of per-query memory tracking.