文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

29.4.6 按线程的预过滤29.4.6 Pre-Filtering by Thread

threads 表包含每个服务器线程的一行。每行包含有关线程的信息,并指示是否为其启用监控。要让 Performance Schema 监控线程,必须满足以下条件:The threads table contains a row for each server thread. Each row contains information about a thread and indicates whether monitoring is enabled for it. For the Performance Schema to monitor a thread, these things must be true:

  • 该thread_instrumentation consumer in the setup_consumers table must be YES.The thread_instrumentation consumer in the setup_consumers table must be YES.

  • threads.INSTRUMENTED 列必须为 YES。The threads.INSTRUMENTED column must be YES.

  • 监控仅针对那些由在 setup_instruments 表中启用的仪器产生的线程事件进行。Monitoring occurs only for those thread events produced from instruments that are enabled in the setup_instruments table.

threads 表还指示每个服务器线程是否执行历史事件记录。这包括等待、阶段、语句和事务事件,并影响对这些表的记录:The threads table also indicates for each server thread whether to perform historical event logging. This includes wait, stage, statement, and transaction events and affects logging to these tables:

events_waits_history
events_waits_history_long
events_stages_history
events_stages_history_long
events_statements_history
events_statements_history_long
events_transactions_history
events_transactions_history_long

要进行历史事件记录,以下条件必须为真:For historical event logging to occur, these things must be true:

  • 必须启用 setup_consumers 表中与历史相关的适当消费者。例如,在 events_waits_history 和 events_waits_history_long 表中记录等待事件,需要相应的 events_waits_history 和 events_waits_history_long 消费者为 YES。The appropriate history-related consumers in the setup_consumers table must be enabled. For example, wait event logging in the events_waits_history and events_waits_history_long tables requires the corresponding events_waits_history and events_waits_history_long consumers to be YES.

  • threads.HISTORY 列必须为 YES。The threads.HISTORY column must be YES.

  • 只有来自在setup_instruments 表中启用的工具的线程事件才会记录日志。Logging occurs only for those thread events produced from instruments that are enabled in the setup_instruments table.

对于前台线程(由客户端连接产生的线程),threads 表中 INSTRUMENTED 和 HISTORY 列的初始值取决于与线程关联的用户帐户是否与 setup_actors 表中的任何行匹配。值来自匹配的 setup_actors 表行的 ENABLED 和 HISTORY 列。For foreground threads (resulting from client connections), the initial values of the INSTRUMENTED and HISTORY columns in threads table rows are determined by whether the user account associated with a thread matches any row in the setup_actors table. The values come from the ENABLED and HISTORY columns of the matching setup_actors table row.

对于后台线程,没有关联的用户。INSTRUMENTED 和 HISTORY 默认都是 YES,并且不参考 setup_actors。For background threads, there is no associated user. INSTRUMENTED and HISTORY are YES by default and setup_actors is not consulted.

初始的 setup_actors 内容如下:The initial setup_actors contents look like this:

mysql> SELECT * FROM performance_schema.setup_actors;
+------+------+------+---------+---------+
| HOST | USER | ROLE | ENABLED | HISTORY |
+------+------+------+---------+---------+
| %    | %    | %    | YES     | YES     |
+------+------+------+---------+---------+

HOST 和 USER 列应包含字面意义的主机名或用户名,或者使用 '%' 来匹配任意名称。The HOST and USER columns should contain a literal host or user name, or '%' to match any name.

ENABLED 和 HISTORY 列表示是否为匹配的线程启用检测和历史事件记录,这取决于之前描述的其他条件。The ENABLED and HISTORY columns indicate whether to enable instrumentation and historical event logging for matching threads, subject to the other conditions described previously.

当性能模式在 setup_actors 中为每个新的前台线程检查匹配时,它会先尝试找到更具体的匹配,使用 USER 和 HOST 列(ROLE 未使用):When the Performance Schema checks for a match for each new foreground thread in setup_actors, it tries to find more specific matches first, using the USER and HOST columns (ROLE is unused):

  • 具有 USER='literal' 和 HOST='literal' 的行。Rows with USER='literal' and HOST='literal'.

  • 具有 USER='literal' 和 HOST='%' 的行。Rows with USER='literal' and HOST='%'.

  • 行的 USER='%' 和 HOST='literal'。Rows with USER='%' and HOST='literal'.

  • 行的 USER='%' 和 HOST='%'。Rows with USER='%' and HOST='%'.

匹配的顺序很重要,因为不同匹配的 setup_actors 行可能具有不同的 USER 和 HOST 值。这使得可以根据 ENABLED 和 HISTORY 列的值,对每个主机、用户或账户(用户和主机组合)选择性地应用仪器和历史事件记录:The order in which matching occurs matters because different matching setup_actors rows can have different USER and HOST values. This enables instrumenting and historical event logging to be applied selectively per host, user, or account (user and host combination), based on the ENABLED and HISTORY column values:

  • 当最佳匹配是一行 ENABLED=YES 时,该线程的 INSTRUMENTED 值变为 YES。当最佳匹配是一行 HISTORY=YES 时,该线程的 HISTORY 值变为 YES。When the best match is a row with ENABLED=YES, the INSTRUMENTED value for the thread becomes YES. When the best match is a row with HISTORY=YES, the HISTORY value for the thread becomes YES.

  • 当最佳匹配是一行 ENABLED=NO 时,该线程的 INSTRUMENTED 值变为 NO。当最佳匹配是一行 HISTORY=NO 时,该线程的 HISTORY 值变为 NO。When the best match is a row with ENABLED=NO, the INSTRUMENTED value for the thread becomes NO. When the best match is a row with HISTORY=NO, the HISTORY value for the thread becomes NO.

  • 当未找到匹配时,该线程的 INSTRUMENTED 和 HISTORY 值均变为 NO。When no match is found, the INSTRUMENTED and HISTORY values for the thread become NO.

setup_actors 行中的 ENABLED 和 HISTORY 列可以独立设置为 YES 或 NO。这意味着您可以单独启用监控,而不必与是否收集历史事件绑定在一起。The ENABLED and HISTORY columns in setup_actors rows can be set to YES or NO independent of one another. This means you can enable instrumentation separately from whether you collect historical events.

默认情况下,监控和历史事件收集会针对所有新的前台线程启用,因为 setup_actors 表最初包含一行,其 HOST 和 USER 都为 '%'。要执行更有限的匹配,例如仅为某些前台线程启用监控,必须修改此行,因为它匹配任何连接,并为更具体的 HOST/USER 组合添加行。By default, monitoring and historical event collection are enabled for all new foreground threads because the setup_actors table initially contains a row with '%' for both HOST and USER. To perform more limited matching such as to enable monitoring only for some foreground threads, you must change this row because it matches any connection, and add rows for more specific HOST/USER combinations.

假设你将 setup_actors 修改如下:Suppose that you modify setup_actors as follows:

UPDATE performance_schema.setup_actors
SET ENABLED = 'NO', HISTORY = 'NO'
WHERE HOST = '%' AND USER = '%';
INSERT INTO performance_schema.setup_actors
(HOST,USER,ROLE,ENABLED,HISTORY)
VALUES('localhost','joe','%','YES','YES');
INSERT INTO performance_schema.setup_actors
(HOST,USER,ROLE,ENABLED,HISTORY)
VALUES('hosta.example.com','joe','%','YES','NO');
INSERT INTO performance_schema.setup_actors
(HOST,USER,ROLE,ENABLED,HISTORY)
VALUES('%','sam','%','NO','YES');

UPDATE 语句将默认匹配更改为禁用仪器化和历史事件收集。INSERT 语句为更具体的匹配添加行。The UPDATE statement changes the default match to disable instrumentation and historical event collection. The INSERT statements add rows for more specific matches.

现在性能模式(Performance Schema)决定如何为新连接线程设置 INSTRUMENTED 和 HISTORY 值,如下所示:Now the Performance Schema determines how to set the INSTRUMENTED and HISTORY values for new connection threads as follows:

  • 如果 joe 从本地主机连接,则该连接匹配第一个插入的行。该线程的 INSTRUMENTED 和 HISTORY 值将变为 YES。If joe connects from the local host, the connection matches the first inserted row. The INSTRUMENTED and HISTORY values for the thread become YES.

  • 如果 joe 从 hosta.example.com 连接,则连接匹配第二个插入的行。线程的 INSTRUMENTED 值变为 YES,HISTORY 值变为 NO。If joe connects from hosta.example.com, the connection matches the second inserted row. The INSTRUMENTED value for the thread becomes YES and the HISTORY value becomes NO.

  • 如果 joe 从任何其他主机连接,则没有匹配。线程的 INSTRUMENTED 和 HISTORY 值变为 NO。If joe connects from any other host, there is no match. The INSTRUMENTED and HISTORY values for the thread become NO.

  • 如果 sam 从任何主机连接,则连接匹配第三个插入的行。线程的 INSTRUMENTED 值变为 NO,HISTORY 值变为 YES。If sam connects from any host, the connection matches the third inserted row. The INSTRUMENTED value for the thread becomes NO and the HISTORY value becomes YES.

  • 对于任何其他连接,HOST 和 USER 设置为 '%' 的行会匹配。现在此行的 ENABLED 和 HISTORY 设置为 NO,因此线程的 INSTRUMENTED 和 HISTORY 值将变为 NO。For any other connection, the row with HOST and USER set to '%' matches. This row now has ENABLED and HISTORY set to NO, so the INSTRUMENTED and HISTORY values for the thread become NO.

对 setup_actors 表的修改仅影响修改后创建的前台线程,而不会影响现有线程。要影响现有线程,请修改 threads 表行的 INSTRUMENTED 和 HISTORY 列。Modifications to the setup_actors table affect only foreground threads created subsequent to the modification, not existing threads. To affect existing threads, modify the INSTRUMENTED and HISTORY columns of threads table rows.