10bet网址
MySQL 8.0参考手册
相关的文档10bet官方网站 本手册下载 本手册节选

27.12.6 Performance Schema Statement Event Tables

性能方案测试语句执行。语句事件发生在事件层次结构的高层。在事件层次结构中,等待事件嵌套在阶段事件中,阶段事件嵌套在语句事件中,语句事件嵌套在事务事件中。

These tables store statement events:

下面几节描述语句事件表。还有汇总语句事件信息的汇总表;看到第27.12.20.3节“报表汇总表”

有关三者之间关系的更多信息events_statements_xxx事件表,请参阅第27.9节“当前和历史事件的性能模式表”

配置语句事件收集

To control whether to collect statement events, set the state of the relevant instruments and consumers:

  • setup_instrumentstable contains instruments with names that begin with声明.使用这些工具可以启用或禁用单个语句事件类的集合。

  • setup_consumerstable 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 theevents_statements_currentevents_statements_history,statements_digest默认情况下,语句消费者是启用的:

mysql> SELECT NAME, ENABLED, TIMED FROM performance_schema。setup_instruments WHERE NAME LIKE 'statement/%';+---------------------------------------------+---------+-------+ | 名字| |定时启用  | +---------------------------------------------+---------+-------+ | 声明/ sql /选择|是的| | |声明/ sql / create_table |是的| | |声明/ sql / create_index |是的| |…| statement/sp/stmt | YES | YES | | statement/sp/set | YES | YES | | statement/sp/set_trigger_field | YES | YES | b| statement/scheduler/event | YES | YES | | statement/com/Sleep | YES | YES | | statement/com/Quit | YES | YES | | statement/com/Init DB | YES | YES |…|声明/文摘/查询|是的| | |声明/文摘/ new_packet |是的| | |声明/文摘/ relay_log | |是的  | +---------------------------------------------+---------+-------+
SELECT * FROM performance_schema。setup_consumersWHERE NAME LIKE '%statements%'; +--------------------------------+---------+ | NAME | ENABLED | +--------------------------------+---------+ | events_statements_current | YES | | events_statements_history | YES | | events_statements_history_long | NO | | statements_digest | YES | +--------------------------------+---------+

要在服务器启动时控制语句事件收集,请在您的my.cnf文件:

  • 启用:

    [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
  • 禁用:

    [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

若要在运行时控制语句事件收集,请更新setup_instruments而且setup_consumers表:

  • 启用:

    更新performance_schema。setup_instrumentsSET ENABLED = 'YES', TIMED = 'YES' WHERE NAME LIKE 'statement/%'; UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME LIKE '%statements%';
  • 禁用:

    更新performance_schema。setup_instrumentsSET ENABLED = 'NO', TIMED = 'NO' WHERE NAME LIKE 'statement/%'; UPDATE performance_schema.setup_consumers SET ENABLED = 'NO' WHERE NAME LIKE '%statements%';

若要只收集特定的语句事件,请只启用相应的语句工具。若要仅为特定语句事件表收集语句事件,请启用语句工具,但只启用与所需表对应的语句使用者。

有关配置事件收集的其他信息,请参见第27.3节“性能模式启动配置”,第27.4节“性能模式运行时配置”

声明中监测

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.

当性能模式检测一个请求(服务器命令或SQL语句)时,它使用从更通用的(或摘要),直到得到最终的乐器名称。

最终仪器名称对应服务器命令和SQL语句:

  • Server commands correspond to theCOM_xxx代码中定义的mysql_com.h头文件和处理sql / sql_parse.cc.的例子是COM_PING而且COM_QUIT.用于命令的工具的名称以声明/ com,如声明/ com/Ping而且声明/ com/Quit

  • SQL statements are expressed as text, such as删除从t1SELECT * FROM t2.用于SQL语句的工具的名称以声明/ sql,如声明/ sql /删除而且声明/ sql /选择

一些最终的仪器名称是特定于错误处理的:

  • 声明/ com/Error服务器接收到的带外消息的帐户。它可以用于检测客户端发送的服务器无法理解的命令。这可能有助于识别配置错误的客户端或使用比服务器新版本的MySQL的客户端,或试图攻击服务器的客户端。

  • 声明/ sql /错误用于解析失败的SQL语句。它可用于检测客户端发送的格式不正确的查询。解析失败的查询与由于执行期间的错误而解析失败的查询不同。例如,SELECT * FROMis malformed, and the声明/ sql /错误使用仪器。相比之下,SELECT *解析,但失败使用没有表错误。在这种情况下,声明/ sql /选择语句事件包含指示错误性质的信息。

请求可以从以下任何来源获得:

  • 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 replica

  • 作为事件调度器中的事件

请求的细节最初是不知道的,性能模式从抽象仪器名称到具体仪器名称的顺序取决于请求的来源。

For a request received from a client:

  1. When the server detects a new packet at the socket level, a new statement is started with an abstract instrument name of声明/文摘/ new_packet

  2. 当服务器读取数据包编号时,它会了解更多关于接收到的请求类型的信息,而性能模式会细化仪器名称。例如,如果请求是一个COM_PINGpacket, the instrument name becomes声明/ com/Ping这就是最后的名字。如果请求是COM_QUERYpacket, 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,声明/文摘/查询, and the request requires further classification.

  3. 如果请求是语句,则读取语句文本并将其提供给解析器。解析之后,确切的语句类型就知道了。例如,如果请求是插入语句,性能架构从其中提炼仪器名称声明/文摘/查询声明/ sql /插入,这是最终的名字。

对于从副本中继日志中读取的请求:

  1. Statements in the relay log are stored as text and are read as such.There is no network protocol, so the声明/文摘/ new_packetinstrument is not used.Instead, the initial instrument is声明/文摘/ relay_log

  2. 当语句被解析时,确切的语句类型是已知的。例如,如果请求是插入语句,性能架构从其中提炼仪器名称声明/文摘/查询声明/ sql /插入,这是最终的名字。

以上描述仅适用于基于语句的复制。对于基于行的复制,可以检测在副本上处理行更改时执行的表I/O,但是中继日志中的行事件不会作为离散语句出现。

对于从事件调度器收到的请求:

The event execution is instrumented using the name声明/调度器/事件.这是最后的名字。

Statements executed within the event body are instrumented using声明/ sql / *名称,不使用任何先前的抽象工具。事件是一个存储程序,存储程序在执行前在内存中预编译。因此,在运行时不进行解析,每个语句的类型在执行时就知道了。

在事件主体中执行的语句是子语句。例如,如果一个事件执行插入语句中,执行的事件本身就是父事件,工具化使用声明/调度器/事件,插入is the child, instrumented using声明/ sql /插入.父/子关系保持不变之间的单独的仪器操作。这与发生的细化顺序不同从抽象仪器名称到最终仪器名称的单一仪器操作。

For statistics to be collected for statements, it is not sufficient to enable only the final声明/ sql / *用于单个语句类型的工具。的abtract声明抽象/ * /还必须启用仪器。这通常不应该是一个问题,因为默认情况下所有语句工具都是启用的。然而,有选择地启用或禁用语句工具的应用程序必须考虑到禁用抽象工具也会禁用单个语句工具的统计信息收集。例如,收集统计信息插入语句,声明/ sql /插入必须启用,但还声明/文摘/ new_packet而且声明/文摘/查询.Similarly, for replicated statements to be instrumented,声明/文摘/ relay_log必须启用。

没有对抽象的工具进行统计声明/文摘/查询because no statement is ever classified with an abstract instrument as the final statement name.