Rechercher dans le manuel MySQL
26.19.1 Query Profiling Using Performance Schema
The following example demonstrates how to use Performance Schema
statement events and stage events to retrieve data comparable to
profiling information provided by SHOW
PROFILES
and SHOW
PROFILE
statements.
The setup_actors
table can be used
to limit the collection of historical events by host, user, or
account to reduce runtime overhead and the amount of data
collected in history tables. The first step of the example shows
how to limit collection of historical events to a specific user.
Performance Schema displays event timer information in
picoseconds (trillionths of a second) to normalize timing data
to a standard unit. In the following example,
TIMER_WAIT
values are divided by
1000000000000 to show data in units of seconds. Values are also
truncated to 6 decimal places to display data in the same format
as SHOW PROFILES
and
SHOW PROFILE
statements.
Limit the collection of historical events to the user that will run the query. By default,
setup_actors
is configured to allow monitoring and historical event collection for all foreground threads:- +------+------+------+---------+---------+
- +------+------+------+---------+---------+
- | % | % | % | YES | YES |
- +------+------+------+---------+---------+
Update the default row in the
setup_actors
table to disable historical event collection and monitoring for all foreground threads, and insert a new row that enables monitoring and historical event collection for the user that will run the query:- mysql> UPDATE performance_schema.setup_actors
Data in the
setup_actors
table should now appear similar to the following:- +-----------+-----------+------+---------+---------+
- +-----------+-----------+------+---------+---------+
- | localhost | test_user | % | YES | YES |
- +-----------+-----------+------+---------+---------+
Ensure that statement and stage instrumentation is enabled by updating the
setup_instruments
table. Some instruments may already be enabled by default.Ensure that
events_statements_*
andevents_stages_*
consumers are enabled. Some consumers may already be enabled by default.Under the user account you are monitoring, run the statement that you want to profile. For example:
- +--------+------------+------------+-----------+--------+------------+
- | emp_no | birth_date | first_name | last_name | gender | hire_date |
- +--------+------------+------------+-----------+--------+------------+
- | 10001 | 1953-09-02 | Georgi | Facello | M | 1986-06-26 |
- +--------+------------+------------+-----------+--------+------------+
Identify the
EVENT_ID
of the statement by querying theevents_statements_history_long
table. This step is similar to runningSHOW PROFILES
to identify theQuery_ID
. The following query produces output similar toSHOW PROFILES
:- +----------+----------+--------------------------------------------------------+
- | event_id | duration | sql_text |
- +----------+----------+--------------------------------------------------------+
- +----------+----------+--------------------------------------------------------+
Query the
events_stages_history_long
table to retrieve the statement's stage events. Stages are linked to statements using event nesting. Each stage event record has aNESTING_EVENT_ID
column that contains theEVENT_ID
of the parent statement.- +--------------------------------+----------+
- | Stage | Duration |
- +--------------------------------+----------+
- | stage/sql/starting | 0.000080 |
- | stage/sql/checking permissions | 0.000005 |
- | stage/sql/init | 0.000052 |
- | stage/sql/optimizing | 0.000006 |
- | stage/sql/statistics | 0.000082 |
- | stage/sql/preparing | 0.000008 |
- | stage/sql/executing | 0.000000 |
- | stage/sql/freeing items | 0.000272 |
- | stage/sql/cleaning up | 0.000001 |
- +--------------------------------+----------+
Traduction non disponible
Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-performance-schema-query-profiling.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.