MySQL Performance Schema
November 10, 2022
A few notes on the MySQL Performance Schema so I don’t forget them.
The performance schema monitors “events”, which is really anything that can be instrumented in the MySQL source code and can be collected.
The performance schema contains tables that represent current events, histories and summaries.
The goal of the performance schema is to introduce very little performance impact.
The MySQL sys table exists to provide more convenient access to performance schema data.
The performance schema is implemented as its own storage engine in MySQL. The data is in memory and lost on server restart.
The performance schema contains these table types
- Setup Tables - configures whats instrumented and whats collected
- Current Events Tables - contain the most recent event for each thread
- History Tables - Contains the most recent 10 events per thread. The “long” table contains the most recent 10,000 events per thread.
- Summary Tables - Aggregation of events, will contain data from events discarded from history table.
- Instance Tables - These tables document what types of objects are instrumented, with names and explainatory notes.
- Misc Tables - everything else
When I was first working with performance schema the meaning of the setup_instruments vs.
the setup_consumers was unclear. I think the documentation on event filtering
is the most clear explaination.
There’s many setup_instruments (>1200 on MySQL 5.7). These are what parts
of the code MySQL will collect events from. But the setup_instruments table
does not determine if the event data will be collected in the schema. Its only
indicating that the instrumentation is enabled. What events are stored in
performance schema is defined in the setup_consumers table. There are 16
setup_consumers on MySQL 5.7.
Its sort of a producer/consumer model where the instruments are what events are being produced and the consumers are how they will be stored.
Once you setup the proper instruments and consumers much data will be collected. To learn about it I recommend reading the upstream documenation, it appears to be the only practical resource.