Rechercher dans le manuel MySQL
26.12.6 Performance Schema Statement Event Tables
[+/-]
The Performance Schema instruments statement execution. Statement events occur at a high level of the event hierarchy. Within the event hierarchy, wait events nest within stage events, which nest within statement events, which nest within transaction events.
These tables store statement events:
events_statements_current
: The current statement event for each thread.events_statements_history
: The most recent statement events that have ended per thread.events_statements_history_long
: The most recent statement events that have ended globally (across all threads).prepared_statements_instances
: Prepared statement instances and statistics
The following sections describe the statement event tables. There are also summary tables that aggregate information about statement events; see Section 26.12.17.3, “Statement Summary Tables”.
For more information about the relationship between the three
events_statements_
event tables, see
Section 26.9, “Performance Schema Tables for Current and Historical Events”.
xxx
Configuring Statement Event Collation
To control whether to collect statement events, set the state of the relevant instruments and consumers:
The
setup_instruments
table contains instruments with names that begin withstatement
. Use these instruments to enable or disable collection of individual statement event classes.The
setup_consumers
table contains consumer values with names corresponding to the current and historical statement event table names, and the statement digest consumer. Use these consumers to filter collection of statement events and statement digesting.
The statement instruments are enabled by default, and the
events_statements_current
,
events_statements_history
, and
statements_digest
statement consumers are
enabled by default:
- FROM performance_schema.setup_instruments
- +---------------------------------------------+---------+-------+
- | NAME | ENABLED | TIMED |
- +---------------------------------------------+---------+-------+
- | statement/sql/create_table | YES | YES |
- | statement/sql/create_index | YES | YES |
- ...
- | statement/sp/stmt | YES | YES |
- | statement/sp/set_trigger_field | YES | YES |
- | statement/scheduler/event | YES | YES |
- | statement/com/Quit | YES | YES |
- | statement/com/Init DB | YES | YES |
- ...
- | statement/abstract/Query | YES | YES |
- | statement/abstract/new_packet | YES | YES |
- | statement/abstract/relay_log | YES | YES |
- +---------------------------------------------+---------+-------+
- FROM performance_schema.setup_consumers
- +--------------------------------+---------+
- | NAME | ENABLED |
- +--------------------------------+---------+
- | events_statements_current | YES |
- | events_statements_history | YES |
- | statements_digest | YES |
- +--------------------------------+---------+
To control statement event collection at server startup, use
lines like these in your my.cnf
file:
Enable:
[mysqld] performance-schema-instrument='statement/%=ON' performance-schema-consumer-events-statements-current=ON performance-schema-consumer-events-statements-history=ON performance-schema-consumer-events-statements-history-long=ON performance-schema-consumer-statements-digest=ON
Disable:
[mysqld] performance-schema-instrument='statement/%=OFF' performance-schema-consumer-events-statements-current=OFF performance-schema-consumer-events-statements-history=OFF performance-schema-consumer-events-statements-history-long=OFF performance-schema-consumer-statements-digest=OFF
To control statement event collection at runtime, update the
setup_instruments
and
setup_consumers
tables:
Enable:
Disable:
To collect only specific statement events, enable only the corresponding statement instruments. To collect statement events only for specific statement event tables, enable the statement instruments but only the statement consumers corresponding to the desired tables.
For additional information about configuring event collection, see Section 26.3, “Performance Schema Startup Configuration”, and Section 26.4, “Performance Schema Runtime Configuration”.
Statement Monitoring
Statement monitoring begins from the moment the server sees that activity is requested on a thread, to the moment when all activity has ceased. Typically, this means from the time the server gets the first packet from the client to the time the server has finished sending the response. Statements within stored programs are monitored like other statements.
When the Performance Schema instruments a request (server command or SQL statement), it uses instrument names that proceed in stages from more general (or “abstract”) to more specific until it arrives at a final instrument name.
Final instrument names correspond to server commands and SQL statements:
Server commands correspond to the
COM_
defined in thexxx
codesmysql_com.h
header file and processed insql/sql_parse.cc
. Examples areCOM_PING
andCOM_QUIT
. Instruments for commands have names that begin withstatement/com
, such asstatement/com/Ping
andstatement/com/Quit
.SQL statements are expressed as text, such as
DELETE FROM t1
orSELECT * FROM t2
. Instruments for SQL statements have names that begin withstatement/sql
, such asstatement/sql/delete
andstatement/sql/select
.
Some final instrument names are specific to error handling:
statement/com/Error
accounts for messages received by the server that are out of band. It can be used to detect commands sent by clients that the server does not understand. This may be helpful for purposes such as identifying clients that are misconfigured or using a version of MySQL more recent than that of the server, or clients that are attempting to attack the server.statement/sql/error
accounts for SQL statements that fail to parse. It can be used to detect malformed queries sent by clients. A query that fails to parse differs from a query that parses but fails due to an error during execution. For example,SELECT * FROM
is malformed, and thestatement/sql/error
instrument is used. By contrast,SELECT *
parses but fails with aNo tables used
error. In this case,statement/sql/select
is used and the statement event contains information to indicate the nature of the error.
A request can be obtained from any of these sources:
As a command or statement request from a client, which sends the request as packets
As a statement string read from the relay log on a replication slave
As an event from the Event Scheduler
The details for a request are not initially known and the Performance Schema proceeds from abstract to specific instrument names in a sequence that depends on the source of the request.
For a request received from a client:
When the server detects a new packet at the socket level, a new statement is started with an abstract instrument name of
statement/abstract/new_packet
.When the server reads the packet number, it knows more about the type of request received, and the Performance Schema refines the instrument name. For example, if the request is a
COM_PING
packet, the instrument name becomesstatement/com/Ping
and that is the final name. If the request is aCOM_QUERY
packet, it is known to correspond to an SQL statement but not the particular type of statement. In this case, the instrument changes from one abstract name to a more specific but still abstract name,statement/abstract/Query
, and the request requires further classification.If the request is a statement, the statement text is read and given to the parser. After parsing, the exact statement type is known. If the request is, for example, an
INSERT
statement, the Performance Schema refines the instrument name fromstatement/abstract/Query
tostatement/sql/insert
, which is the final name.
For a request read as a statement from the relay log on a replication slave:
Statements in the relay log are stored as text and are read as such. There is no network protocol, so the
statement/abstract/new_packet
instrument is not used. Instead, the initial instrument isstatement/abstract/relay_log
.When the statement is parsed, the exact statement type is known. If the request is, for example, an
INSERT
statement, the Performance Schema refines the instrument name fromstatement/abstract/Query
tostatement/sql/insert
, which is the final name.
The preceding description applies only for statement-based replication. For row-based replication, table I/O done on the slave as it processes row changes can be instrumented, but row events in the relay log do not appear as discrete statements.
For a request received from the Event Scheduler:
The event execution is instrumented using the name
statement/scheduler/event
. This is the final
name.
Statements executed within the event body are instrumented using
statement/sql/*
names, without use of any
preceding abstract instrument. An event is a stored program, and
stored programs are precompiled in memory before execution.
Consequently, there is no parsing at runtime and the type of
each statement is known by the time it executes.
Statements executed within the event body are child statements.
For example, if an event executes an
INSERT
statement, execution of
the event itself is the parent, instrumented using
statement/scheduler/event
, and the
INSERT
is the child, instrumented
using statement/sql/insert
. The parent/child
relationship holds between separate
instrumented operations. This differs from the sequence of
refinement that occurs within a single
instrumented operation, from abstract to final instrument names.
For statistics to be collected for statements, it is not
sufficient to enable only the final
statement/sql/*
instruments used for
individual statement types. The abtract
statement/abstract/*
instruments must be
enabled as well. This should not normally be an issue because
all statement instruments are enabled by default. However, an
application that enables or disables statement instruments
selectively must take into account that disabling abstract
instruments also disables statistics collection for the
individual statement instruments. For example, to collect
statistics for INSERT
statements,
statement/sql/insert
must be enabled, but
also statement/abstract/new_packet
and
statement/abstract/Query
. Similarly, for
replicated statements to be instrumented,
statement/abstract/relay_log
must be enabled.
No statistics are aggregated for abstract instruments such as
statement/abstract/Query
because no statement
is ever classified with an abstract instrument as the final
statement name.
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-performance-schema-statement-tables.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.