Lesson 7 of 9 · 24m
Performance Schema: Diagnosing Real Slowdowns
Use Performance Schema and the sys schema to find expensive statements, waits, lock contention, and replication bottlenecks without cargo-cult tuning.
The slow query log tells you that a query was slow. Performance Schema tells you what the server was doing while the database burned. It is the difference between a witness statement and a flight recorder. Learn to read the flight recorder before reaching for random configuration changes.
Check the baseline first
SHOW VARIABLES LIKE 'performance_schema';Performance Schema is normally enabled, but consumers and instruments determine how much detail is collected. Collection is cheap compared with blind guessing, though it is not literally free. On very hot systems, enable additional instruments deliberately rather than turning on everything forever.
Start with statement digests
SELECT DIGEST_TEXT, COUNT_STAR, SUM_TIMER_WAIT,
SUM_ROWS_EXAMINED, SUM_ROWS_SENT
FROM performance_schema.events_statements_summary_by_digest
ORDER BY SUM_TIMER_WAIT DESC
LIMIT 10;This table groups normalized statements, which matters more than one dramatic execution. A query taking 80 milliseconds but running 50,000 times an hour can cost more total time than the five-second report running twice a day. The digest tells you where server time actually went.
The sys schema wraps many Performance Schema tables in friendlier views for triage and formats many raw picosecond timers readably:
SELECT * FROM sys.statements_with_full_table_scans LIMIT 10;
SELECT * FROM sys.statements_with_sorting LIMIT 10;Waits tell you where time sleeps
Waits are time spent blocked: disk IO, mutexes, locks, network, and other internal resources.
SELECT EVENT_NAME, COUNT_STAR, SUM_TIMER_WAIT
FROM performance_schema.events_waits_summary_global_by_event_name
ORDER BY SUM_TIMER_WAIT DESC
LIMIT 15;High IO waits plus physical reads point toward storage or cache pressure. High lock waits suggest contention rather than a missing index. Do not tune innodb_buffer_pool_size because the word 'io' appeared; correlate the wait evidence with query and operating-system metrics.
Lock contention has a live view
SELECT * FROM performance_schema.data_locks;
SELECT * FROM sys.innodb_lock_waits;In MySQL 8, data_locks replaces older lock tables and shows which transaction is blocking which victim. Pair it with information_schema.innodb_trx and thread details. MariaDB exposes its own information schema tables and version-specific performance schema coverage, so verify exact table names on the server in front of you.
Replication instrumentation is part of performance work
Performance Schema exposes connection and applier status tables. When a replica falls behind, these tables show whether the bottleneck is network receipt, a single-threaded apply stream, a long transaction, or worker stalls. That distinction decides whether you change parallelism, batching, indexing, or network plumbing.
Field notes
- Digest tables are fixed-size and can evict entries on busy servers; export or aggregate continuously if you need history.
EXPLAINtells you the optimizer's plan. Performance Schema tells you what actually consumed time. You need both.- Resetting statistics during an incident destroys evidence. Capture before you clear.
Was this lesson helpful?